Time interpolation is useful in multiplayer games for things like elevators, doors and even trains.
In Multiplayer game it is important that things are in sync with Client and Server. This means that we wan’t moving objects to be in same location on client as they are in server, at the same time. If you have somekind of moving platform and characters end up on it (like elevator) and it’s not perfectly in same location where it is on server (frame & time), result is that characters lag and warp.
This is where time interpolation comes in. When server and client clocks are almost perfectly in sync we can calculate transforms just with one datetime and timespan values.
What we need?
We need to create a timestamp on server from utc time and then we need duration, for how long it’s going to take time to go from Point A to Point B.
Then we need to define two locations. Start location and end location.
Once we have start time and duration we can turn it into value of 0 – 1.
We feed this value into function called Ease.
Time interpolation function:
Inputs and outputs.
- TimeStart – Datetime of when this interpolation starts.
- Tick – Input UTCNow function here.
- Duration – How long it takes to get to the end, from 0 to 1.
- Time Difference – The difference of utc clock between client and server. Sometimes there’s 1 or 2 second difference.
- Clamp – If you wan’t to clamp the result in between 0 & 1. Useful if you add 2 second delay before it start, unless you start it right away.
- Alpha – Result in 0 & 1 range.
- InverseAlpha – Same as above but goes from 1 to 0.
- Clock Timespan – How much time is left as Timespan.
- Clock Delta – Clock difference in seconds.
- Clock Delta Inverse – Reversed.
- Max Seconds – Duration in seconds.
- IsFinished? – Tell’s if this is over.
- Rounds – Gives you repeate count. Works if you don’t enable Clamp.
Timestamp structure i’m using. Replicate this to client’s where it goes into time interpolation function, take output value Alpha, this is where the result comes out.
Make sure you input some values into Duration and Time Start otherwise if you just input zero values it will divide with zero which will result with infinite value.
Will this fix my laggy Elevators?
Yes. Put the SetWorldLocation in Elevator’s tick, if you put it anywhere else the elevator will lag and so will the characters. It only work’s with elevators tick event and not in scene component or actor component. It has something to do with proper Delta Time.
Will this fix my laggy Doors?
Yes. After this characters can hug the doors and it will not push them back when the door is opening.
Can i drive train with this (following point to point or curve paths)?
Yes. Timestamp every train driving action. Acceleration, stop and what else there is?
Multiplayer Spaceships (characters walking inside)?
Should work. Just stay away from Physics On.
I still don’t get it
If you need more information just email me, mail in About.
[…] There’s also a short Time Interpolation tutorial […]