Spawning a projectile on server is laggy on the client

Hey,

I have an actor that spawns on the server, and as you know what ever you spawn on the server will spawn on the client.

	bReplicateMovement = true;
	bReplicates = true;
	bAlwaysRelevant = true;

This is a rocket, and it looks smooth in the server window, but on the client it is very choppy.

How can I synchronize the positions on the client, so it looks smoother?

I’m happy with theoretical answers.

Right, so I have no fix for this.

I thought UE4 would have handles physics networking, it appears not.

I have no clue why it’s coppy.

You should simulate physics on the server only and store the transforms of the server side version actor in a replicated variable.

Then on the client side versions of your actor you can Lerp smoothly from the client side actor’s world transform to the server side actor’s world transform (which is stored in the replicated variable). This way you don’t want to enable built-in movement replication as you have your own replication for that.

Sorry for Hungarian notes on the picutre, initially made this for someone else.

Pink note: If I’m a server side clone, I let simulate physics. (by default, I turned off physics simulation on the actor)

Gray note: If I’m a server side clone, I store my transform in a replicated variable.

Blue note: If I’m a client side clone, I smoothly interpolate my transform to the server side clone’s transform.

Using Switch Has Authority to check if it’s a server side version (Authority) or client side version (Remote).

Edit: I see you use C++, you can apply the same in code as well if you don’t want to use blueprints.

MartinF, you beautiful man.

I never knew Projectile Movement had an activate method!

I will test this when I am home. That explanation was A*. If the test’s are correct, then I’ll answer. An answer worth Caching!. The same can be applied for a physics ball do you think? Or do you think this will desync. Cheers.

Works same with a physics ball, or any movement.

hi, for now I ticked answer. It’s not that smooth, but it’s better than 3fps.

The lower the Alpha value on your lerp, the smoother the movement gets. Make sure you call it every frame.

SphereComponent->SetWorldLocation(FMath::Lerp(SphereComponent->GetComponentTransform().GetLocation(), myTrans.GetLocation(), 0.2f));
SphereComponent->SetWorldRotation(FMath::Lerp(SphereComponent->GetComponentTransform().GetRotation(), myTrans.GetRotation(), 0.2f));

this is called every every frame. 0.2f was 0.01f, it is smooth, but out of sync.

myTrans is the replicated variable.

0.1f is okay, but still choppy.

It’s okay for me needs.