I am working on interpolating movement and am displeased by the results I am getting.
The results are alright I guess? I think it isnt so great if I am spectating someone though…
(tested only on localhost so far)
Here is an example of how I am doing things.
Click for code
float updateRate = 20;
//...
public void Update()
{
Vector3 prevPos = transform.position;
currentInterpolateTime += (Time.deltaTime * updateRate);
transform.position = Vector3.Lerp(startPosition, targetPosition, currentInterpolateTime);
//Check to see if we ever move backwards.
Debug.DrawRay(transform.position, (Vector3.up + ExtVector3.Direction(prevPos, transform.position)) * 2f, Color.yellow, 1f);
//Check to see our movement consistency.
Debug.DrawRay(transform.position, Vector3.up * (Vector3.Distance(prevPos, transform.position) / Time.deltaTime), Color.green, 2f);
}
//This is called before Update
protected override void OnAfterDeserialize()
{
startPosition = transform.position;
targetPosition = position.value;
currentInterpolateTime = 0;
}
Here is an image example
Note that I am just moving at a consistent rate on the server side, and this is the result on the client side.
Click for image
As you can see by the image, basically each time we receive an updated position packet, the distance is different, which seems to cause inconsistencies in the movement between each update position packet.
This may be due to the other side not exactly sending every so and so time since its running at 60fps and the sendrate is 20 times a second, so there can be a 16ms difference in distance etc…(remember, this is just localhost so far).
What I want to ask is, is this to be expected? Is it just not possible to really lerp smoothly across all movement update packets with the current info I am sending?
Is there anything I can do to improve this?
For example, I see people talk about valves article on entity interpolation and what not with buffered states, but I am confused on a few things. Some source codes of interpolation I see people just store the currentTime of their own client when they receive the packet and what not, while in other source codes I see people having the server send the time the packet was sent and then using that as the time for when calculating the interpolation.
I have tried the client time way, but not the server network time way.
Is using the network time the way to get proper smoothed movement over the network?
Am I meant to also include the velocity and what not to try and lerp smoothly somehow?
For right now I am not worrying about extrapolation or anything, so is sending the velocity not needed?
Any insight is appreciated.
I have read multiple articles on this, but I guess either my expectations are too high, or I am just not sending/using enough data to properly just guess the new position instead of just relying on lerp?