PredictedObjectOwnerSmoother Improvement #503
Closed
Xelopie
started this conversation in
Feature Request
Replies: 2 comments
-
reference source: https://kinematicsoup.com/news/2016/8/9/rrypp5tkubynjwxhxjzd42s3o034o8 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Added/not relevant anymore. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The original implementation is good enough for most cases. Still, I have seen many FN users claiming that jittering happens when being as the owner of the object (no jittering for non-owned object). Most of us also use a smooth follow camera for the character, which could just make the problem much obvious. I have just come across this problem as well and spent a couple of days on it. And finally got some progress!
By recording the game and playing it back frame by frame, you can see that the jitter is not "going back and forth" (with fixed camera). It is moving forward with inconsistent speed only which causes an illusion of jittering. If using smooth follow camera with character moving at constant speed, there will be some frames where the object suddenly stops but the camera keep moving forward (kinda looks like jittering).
Straight to the code: (see the CHECK THIS tag)
First, the SetGraphicalMoveRates() method, which is called before ticking.
Second method, MoveToTarget(), called on TimeManager.OnUpdate
Some simple maths here to illustrate the problem:
Put them into an actual use case.
Let say if the Time.time is exactly 1 now, and TimeManager runs from the beginning.
Time.time = 1 (ticked in this frame)
If you spend >0.02 sec to go to next frame, let say 0.03 sec (Time.deltaTime = 0.03)
At Time.time = 1.03 sec (ticked in this frame because >0.02, Time.deltaTime = 0.03)
When distance to interpolate = 10 units (object position at Time=1: 0; object position at Time=1.03: 10)
TickDelta = 0.02 sec (50 ticks/sec)
position move rate = 10/0.02 = 500 units/sec
If you follow the AfterTick update order in TimeManager, OnUpdate will be called after PostTick.
At this point, in MoveToTarget() method, _positionMoveRate * delta = 500 * 0.03 = 15 units ???????????????????
15 is even larger than 10 which is the distance you should interpolate. Of course, by using Vector3.MoveTowards, the final value will be clamped by target. But this update will still shoot your character straight to the real object position, which means no interpolation at all.
The correct interpolation distance should be:
_positionMoveRate * (excess deltaTime after minus TickDelta)
= 500 * (0.03 - 0.02)
= 5 units (the graphic aspect had been reset back to default position already in PreTick)
A quick fix from my version of NetworkRigidbody
This has greatly reduced the jittering caused by inconsistent interpolation even when moving at constant speed while I have only tested in the "TimeManager update order: After Tick" setup (my game follows this setup).
Hope this can help.
Beta Was this translation helpful? Give feedback.
All reactions