Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Spawning a projectile on server is laggy on the client


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.

Product Version: UE 4.9
more ▼

asked Apr 13 '16 at 07:31 PM in C++ Programming

avatar image

219 19 17 24

avatar image Moynzy Apr 14 '16 at 09:38 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

alt text

more ▼

answered Apr 15 '16 at 04:16 PM

avatar image

21 2 6

avatar image Moynzy Apr 16 '16 at 03:05 PM

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.

avatar image KRAKZZ Apr 16 '16 at 04:11 PM

Works same with a physics ball, or any movement.

avatar image Moynzy Apr 17 '16 at 05:57 PM

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

avatar image KRAKZZ Apr 17 '16 at 06:20 PM

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

avatar image Moynzy Apr 17 '16 at 06:25 PM
         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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question