void AShip::Tick(float DeltaSeconds)
{
// Update AActor, including physics.
Super::Tick(DeltaSeconds);
if (HasAuthority())
{
TargetMovementData.Location = GetActorLocation();
TargetMovementData.Rotation = GetActorRotation();
TargetMovementData.LinearVelocity = MeshComponent->GetPhysicsLinearVelocity();
TargetMovementData.AngularVelocity = MeshComponent->GetPhysicsAngularVelocity();
}
else
{
if (IsLocallyControlled())
{
FVector LerpPos;
FRotator LerpRot;
FVector LerpVel;
FVector LerpAngVel;
LerpPos = FMath::VInterpConstantTo(GetActorLocation(), TargetMovementData.Location, DeltaSeconds, 0.01f); // have tried different values for this 'speed' argument (0.1 to 0.001). Same results.
LerpRot = FMath::RInterpConstantTo(GetActorRotation(), TargetMovementData.Rotation, DeltaSeconds, 0.01f);
LerpVel = FMath::VInterpConstantTo(MeshComponent->GetPhysicsLinearVelocity(), TargetMovementData.LinearVelocity, DeltaSeconds, 0.01f);
LerpAngVel = FMath::VInterpConstantTo(MeshComponent->GetPhysicsAngularVelocity(), TargetMovementData.AngularVelocity, DeltaSeconds, 0.01f);
SetActorLocation(LerpPos);
SetActorRotation(LerpRot);
MeshComponent->SetPhysicsLinearVelocity(LerpVel);
MeshComponent->SetAllPhysicsAngularVelocity(LerpAngVel);
}
else
{
SetActorLocation(TargetMovementData.Location);
SetActorRotation(TargetMovementData.Rotation);
MeshComponent->SetPhysicsLinearVelocity(TargetMovementData.LinearVelocity);
MeshComponent->SetAllPhysicsAngularVelocity(TargetMovementData.AngularVelocity);
}
}
}
With the above, my clients often see their own movement really slowly (they rotate much slower than they do on the screen of the listen server, and slower than they should in general), and thus desynced from the server - their ‘up’ direction is not used for physics, but rather the server’s opinion on their ‘up’ direction, and so on.
Additionally, I can’t see the rotations of other clients, and I think the location stuff is slightly out of sync, too.
I’m not sure how to correct this, or to do something like having collisions work only on the server.
Any ideas?