Hello guys. I’m struggling with a problem for a time already and I don’t understand why it’s happening and how to solve it.
I have a flying pawn, flying at a normal speed of 80. Everything is replicated as expected, the moving forward and rotation are very smooth, but, in case I increase the speed to 280, the rotation is jittery. This is only on the others client view.
void ADragon::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FlyingSpeed = UKismetMathLibrary::FInterpTo(FlyingSpeed, TargetSpeed, DeltaTime, FlyingInterSpeed);
AddActorLocalOffset(FVector(FlyingSpeed,0.0f,0.0f),true);
if(GetLocalRole() == ROLE_AutonomousProxy)
{
UpdateServerTransform(DragonCollision->GetRelativeTransform());
}
}
//Checking if my speed is greater than the max speed and not going through walls. None of the logs are triggered.
void ADragon::UpdateServerTransform_Implementation(FTransform Transform)
{
float Now = GetWorld()->GetRealTimeSeconds();
if (SpeedCheckLastTime == 0)
{
SpeedCheckLastTranslation = Transform.GetTranslation();
SpeedCheckLastTime = Now;
SpeedCheckTranslationSum = FVector::ZeroVector;
SpeedCheckTranslationCount = 0;
}
else
{
SpeedCheckTranslationSum += Transform.GetTranslation();
SpeedCheckTranslationCount++;
if (Now - SpeedCheckLastTime > SpeedCheckInterval)
{
FVector SpeedCheckTranslation = SpeedCheckTranslationSum / SpeedCheckTranslationCount;
float Distance = FVector::Distance(SpeedCheckLastTranslation, SpeedCheckTranslation);
float Speed = Distance / (Now - SpeedCheckLastTime);
SpeedCheckLastTime = Now;
SpeedCheckTranslationSum = FVector::ZeroVector;
SpeedCheckTranslationCount = 0;
if (FlyingSpeed > BoostSpeed * 1.05f)
{
UE_LOG(LogTemp, Log, TEXT("TargetSpeed ------- %f"), TargetSpeed);
UE_LOG(LogTemp, Log, TEXT("Flyingspeed ------- %f"), FlyingSpeed);
UE_LOG(LogTemp, Log, TEXT("Moving too fast ------- %f"), SpeedCheckTranslation.X);
UpdateClientTransform(FTransform(DragonCollision->GetRelativeRotation(), SpeedCheckLastTranslation));
return;
}
SpeedCheckLastTranslation = SpeedCheckTranslation;
}
}
DragonCollision->SetRelativeTransform(Transform,true);
FHitResult HitResult;
if (HitResult.bBlockingHit) {
MovesWithHits++;
UE_LOG(LogTemp, Log, TEXT("Calculate number of hits %u"),MovesWithHits);
}
else {
MovesWithHits = 0;
}
if (MovesWithHits > MaxMovesWithHits) {
UpdateClientTransform(DragonCollision->GetRelativeTransform());
UE_LOG(LogTemp, Log, TEXT("Moving too fast"));
}
}
void ADragon::UpdateClientTransform_Implementation(FTransform Transform)
{
DragonCollision->SetRelativeTransform(Transform);
}
void ADragon::MouseX(float Val)
{
ProcessRoll(Val);
if(GetLocalRole() != ROLE_Authority)
{
FRotator CurrentRotation = GetActorRotation();
FRotator NewRotation(0, Val * MouseSensitivity, 0);
FRotator ResultRotation = CurrentRotation + NewRotation;
DragonCollision->SetRelativeRotation(ResultRotation);
ProcessSpringArmOffset(Val);
}
}
void ADragon::MouseY(float Val)
{
if(GetLocalRole() != ROLE_Authority)
{
FRotator CurrentRotation = GetActorRotation();
FRotator NewRotation(Val * MouseSensitivity,0, 0);
FRotator ResultRotation = CurrentRotation + NewRotation;
ResultRotation.Pitch = FMath::Clamp(ResultRotation.Pitch,MouseMinY,MouseMaxY);
DragonCollision->SetRelativeRotation(ResultRotation);
}
}
Anyone know what’s the problem and how to solve it? Thank you!