Hi I’m beginner of ue4 network programming.
I am making multiplay shooting game.
A pawn in my game is replicated actor, so it run perfectly no problem with replicates location and rotation.
but my problem is when over 6 players connected on server. other player movement look like teleport.
I want to look like other client move smoothly.
this is my pawn update code
MyPawn::Tick(float DeltaTime)
{
if (IsLocallyControlled())
{
FTransform t = GetActorTransform();
FVector _location = t.GetLocation();
FRotator _rotation = FRotator(t.GetRotation());
FVector _replocation = Rep_PawnTransform.GetLocation();
FRotator _reprotation = FRotator(Rep_PawnTransform.GetRotation());
float length = fabs((_location - _replocation).Size());
if (length > LocationUpdateOffset && !bSyncLocationToServer)
{
ServerRPCMovement(t);
bSyncLocationToServer = true;
}
else
{
bSyncLocationToServer = false;
}
float angle = acosf(FVector::DotProduct(_rotation.Vector(), _reprotation.Vector())) * (180.0f / PI);
if (angle > RotationUpdateOffset && !bSyncRotationToServer)
{
ServerRPCMovement(t);
bSyncRotationToServer = true;
}
else
{
bSyncRotationToServer = false;
}
}
else
{
FVector currentLocation = GetActorLocation();
FVector targetLocation = Rep_PawnTransform.GetLocation();
FVector _repLocation;
_repLocation = FMath::VInterpConstantTo(GetActorLocation(), Rep_PawnTransform.GetLocation(), DeltaTime, _LocationInterpSpeed);
FRotator currentRotation = GetActorRotation();
FRotator targetRotation = FRotator(Rep_PawnTransform.GetRotation());
FRotator _repRot;
targetRotation.Yaw = FRotator::NormalizeAxis(targetRotation.Yaw);
_repRot = FMath::RInterpConstantTo(GetActorRotation(), FRotator(Rep_PawnTransform.GetRotation()), DeltaTime, _RotationInterpSpeed);
SetActorLocation(_repLocation);
SetActorRotation(_repRot);
}
}
Do I must fix this code? or other way for smooth movement.
help me.