Hi Everyone,
This issue seems to be everywhere in the literature (other questions and countless tutorials/guides). The set up is: player one (running the server) has a cube as does player two (running a client). They race to FVector (100.f,0.f,0.f) through the GameMode and every time the server will win. If we add player three and player four, player one will still win but it will be a three-way tie for second.
Tick controls movement:
void APlayer_Cube::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
if (bMove) {
Movement(FMath::VInterpConstantTo(GetActorLocation(), FinalPosition, DeltaSeconds, FVector::Distance(StartPosition, FinalPosition) / ActionTimer));
}
}
So game mode flags bMove and the race begins.
For clarity the movement is:
void APlayer_Cube::Movement(FVector MovePosition) {
if (GetLocalRole() < ROLE_Authority) { Server_Movement(MovePosition); }
else { SetActorLocation(MovePosition);}
}
void APlayer_Cube::Server_Movement_Implementation(FVector MovePosition) { Movement(MovePosition); }
Also note that I graphed the difference between the current position and next position for each cube:
You can see that the first one is relatively constant (the server cube) and the others osscilate randomly between 0 and 5.
A solution however, is to add an additional ServerActorLocation(MovePosition) just after the if else. What this does: it moves on the client and the server then catches up…because the server doesn’t talk to the client every tick or something like that. The issue this causes, as to be expected, is jittery movement.
If you got to this part and it made sence please help me clean this up. What I want: non-jittery movement where the server and client arrive at the Final position simulataniously.
Thanks Everyone