I am trying to create a snake where body links follow the target in front of them, while the head moves forward at a constant rate. However, when playing as a client or with more then 2 clients connected, the body actors will start to jitter.
See video - Two Heads spawn with 20 bodies attached, Left is Server Right is Client.
The actors that are moving are based off the ACharacter Object and are using the Character Movement component with both Replicates and Replicates movement flagged.
The Follow Code which is currently being called via tick:
if (!IsBody())
{
return;
}
if (!Target)
{
return;
}
FVector TL = Target->GetActorLocation();
FVector Direction = TL - GetActorLocation();
Dis = Direction.Size();
float MoveScale = Dis / IdealDistance;
if (Target->IsHead())
{
MoveScale = 1;
}
if (Dis < 0)
{
return;
}
Direction.Normalize();
float MoveSpeed = MovementSpeed;
float DeltaTime = GetWorld()->GetDeltaSeconds();
if (DeltaTime >= 0.4f)
{
return;
}
FVector Movement = Direction * MoveSpeed * DeltaTime * MoveScale;
FRotator Rotation = Direction.Rotation();
FHitResult Hit(ForceInit);
GetCharacterMovement()->SafeMoveUpdatedComponent(Movement, Rotation, true, Hit);
if (Hit.IsValidBlockingHit())
{
const FVector Normal = Hit.Normal.GetSafeNormal();
const FVector Deflection = FVector::VectorPlaneProject(Movement, Normal) * (1.0f - Hit.Time);
GetCharacterMovement()->SafeMoveUpdatedComponent(Deflection, Rotation, true, Hit);
}
I have tried calling this with Authority, but that only increases the jitter.
If anyone has any suggestions i would appreciate it.
Thanks