Hello,
I am creating a host/client game where both players run around inside of a ball. Think chained together + monkey ball. I am having an issue where the ball is experiencing some jitter on the client. This gets much worse when simulating a “bad” network environment. The Network Profiler tool does not point out any glaring issues with the data I’m sending over the network. Below is my code, I thought maybe binding AddForce to my character Move “triggered” method might be too much to send over the network, but I tested using just “started” and still saw a fair amount of jitter. The client-side jitter seems to happen to the UStaticMeshComponent whenever it moves. Any ideas or help are appreciated, thank you!
void ABuddiesCharacter::Move(const FInputActionValue& Value)
{
// Input is a Vector2D
FVector2D MovementVector = Value.Get<FVector2D>();
if (Controller != nullptr)
{
// Find out which way is forward
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// Get forward vector
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
// Get right vector
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
// Add movement input to the character
AddMovementInput(ForwardDirection, MovementVector.Y);
AddMovementInput(RightDirection, MovementVector.X);
if (IsLocallyControlled())
{
if(HasAuthority())
{
FVector ForwardForce = ForwardDirection * MovementVector.Y * ForceScale;
FVector RightForce = RightDirection * MovementVector.X * ForceScale;
FVector TotalForce = ForwardForce + RightForce;
BallActor->AddForceToBall(TotalForce);
}
else
{
ServerApplyForceToBall(ForwardDirection, RightDirection, MovementVector);
}
}
}
}
void ABuddiesBall::AddForceToBall(FVector Force)
{
if(HasAuthority())
{
SphereComponent->AddForce(Force);
}
}
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = “Components”, meta = (AllowPrivateAccess = “true”))
UStaticMeshComponent* SphereComponent;