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"

What is the best way to smooth player movement for network hiccups? Interp? Ease? (no physics)

So my online multiplayer game has simple 6DOF movement using the floating pawn movement class. When you move in any direction, the speed is 3500 - no acceleration, no physics force. You just go 3500 immediately. I set up my simple server movement replication like so and it works perfectly with a good connection:

alt text

But of course, on worse CPUs/network connections it can look jittery. For my case, what is the best way to "smooth" the jitter so that when the affected character's movement replicates to other clients it doesn't jitter or teleport but rather moves smoothly in the predicted vector? I imagine it's one of the VInterp or Ease functions, but I am at a loss where to get a sort of "previous actor location" so that the two vectors I am easing from and to are legit. In other words, Interp and Ease require two vectors to smooth. I can get the current actor location, but what is the other vector I am trying to get? Is there another way to accomplish the fakery I'm trying to achieve?

For good measure, here are three ways that aren't working really, but are doing something. The Ease function seems to smooth the best but I am basically using the same location from a few ticks before to simulate a "previous" actor location.

alt text

To sum up what I am trying to achieve: I don't want my players to see enemies teleport/jitter when there are network or client updating hiccups. I'd rather see a smooth "catching up" to where the enemy now is. (I think some call this rubber banding?)


Product Version: UE 4.12
more ▼

asked Aug 31 '16 at 06:35 PM in Blueprint Scripting

avatar image

56 6 8 10

avatar image VictorBurgos Sep 12 '16 at 05:40 PM

I'm going to write a comment, rather than answer, because I am not an expert on Multiplayer (yet...) but, I know that there is a practice where you actually MOVE the player on the client at the same time as the SERVER.

This doesn't really answer your question, so I apologize, but this resource may help you understand some things if you haven't already used this: http://gafferongames.com/networking-for-game-programmers/

Also this post may help you: https://forums.unrealengine.com/showthread.php?102432-Lack-of-Movement-Components-for-Networking&p=490620&viewfull=1#post490620

avatar image EchoHeadMatt Sep 12 '16 at 07:26 PM

Yep, I scrubbed those already. I appreciate the info though! I'll take what I can get. I do hope there is a more simple solution exposed in BP that can get what I need. Hoping someone from Epic will see this and take a crack at it! :)

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

1 answer: sort voted first

Hi Matt!

Well there are a few approaches, but I'm going to suggest one that I think will be pretty straightforward and fairly robust in most situations.

First of all, I'm assuming you're talking about smoothing the location of other players you see when playing, not your own player. Those are two different problems really (and the first is the easier to solve).

First of all, you'll want to be able to detect whether the client has been moved by a network update. In blueprints this is a little messy with Blueprint-only projects right now as we do not have a callback to tell you the network update happened. The most reliable way to do this is probably have your own replicated location, rotation, and possibly velocity set by the server each update, and catch the RepNotify event for that struct on the client (In blueprints select "RepNotify" under "Replication" for your variable). When the client detects that the network location from the server arrives, this is your "new" server location. You can then choose how to use this new location.

One approach (the simplest) would be to turn off the "Replicate Movement" flag on the actor, and do the interpolation yourself to the server location on the client. Turning off this flag means the server won't do the normal replicate and change of location for the client that happens automatically. Then you could do an interpolation in the tick for the client from current position to the server replicated position, however you like (EaseIn, Lerp, etc). (By the way, make sure you are factoring in the Alpha or DeltaTime parameters to your Ease or Lerp functions!)

Alternatively, you can leave replicated movement on (meaning the root component will teleport to the server location when it's updated), but interpolate another part of your pawn to that location instead. For instance, say you have a sphere collision root, and an attached mesh. You could let the server teleport the sphere, and update the relative location of the mesh to "undo" the server change, essentially leaving it in the spot in the world. In code this looks like this (I've simplified it to make it more readable I hope, even if you aren't a programmer):

         // The mesh doesn't move, but the collision root does so we have a new offset.
         FVector NewToOldVector = (OldLocation - NewLocation);
         float Distance = NewToOldVector.Size();
         if (Distance > MaxSmoothNetUpdateDistance)
             // We would move too far, so make the offset zero (warp to the root)
             MeshTranslationOffset = FVector::ZeroVector;
             MeshTranslationOffset = MeshTranslationOffset + NewToOldVector;    

Then each tick you decay the relative offset of the mesh towards zero, meaning you try to move it back to the root position. This is similar to how the engine code does this for Characters (UCharacterMovementComponent::SmoothCorrection figures out MeshTranslationOffset based on the change in location, and SmoothClientPosition_Interpolate decays it toward zero with some simple code (again simplified):

            if (DeltaSeconds < SmoothLocationTime) // SmoothLocationTime is about 0.125 secs
             // Slowly decay translation offset
             MeshTranslationOffset = MeshTranslationOffset * (1.f - DeltaSeconds / SmoothLocationTime);
             MeshTranslationOffset = FVector::ZeroVector;
         FVector NewRelTranslation = GetComponentToWorld().InverseTransformDirection(MeshTranslationOffset) + DefaultMeshOffset;

The advantage here is that your are moving the invisible gameplay-relevant collision to exactly match the server collision as soon as possible, but slowly moving the visual representation (the mesh) over time to reduce choppiness.

Both approaches mentioned above should be compatible with continuing to update locations based on a velocity during Tick, which will further maintain the smooth look on clients.

Hope this helps!

(Note: in code, detecting the network change in location is much easier, you override PostNetReceiveLocationAndRotation() and you can record the change in location, knowing this came from a network update).

more ▼

answered Sep 12 '16 at 10:45 PM

avatar image

zeroexception STAFF
1k 18 16 39

avatar image EchoHeadMatt Sep 13 '16 at 03:07 PM

Thank you, Zak. Both make sense to me and being a blueprint-only hopeful, this will take time to digest. But if nothing else, I have some good engineers who'd get this to happen. Thanks for this!

avatar image Mamba Jul 20 '17 at 06:15 AM

Hello there, EchoHeadMatt. If possible I would really love to speak with you about some of the things you have been doing in your project as I really think they might help me with my significant road block in my own. Please let me know if it would be possible to have a brief discussion on character replication and movement. Thanks so much!

(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