Ghost car movement jitters when replaying previous race
I'm having an issue with the movement of my replay being jittery. I've tried various different implementations for moving using lerp, slerp, and smoothstep, which each still jittering some what. I found this post, which has the same issue. He seems to suggest it's the physics system causing the problem. The only thing is my ghost car doesn't have any rigid bodies attached to it.
Here's what my Update currently looks like:
void Update ()
{
if (GhostCar.Instance.HasPositions)
{
GhostCar.Instance.GrabNextPosition();
time += GhostCar.Instance.GetDeltaTime();
if (time >= GhostCar.Instance.UpdateFrequency)
{
time = 0f;
previousPosition = transform.position;
}
transform.position =
Vector3.Slerp
(
previousPosition,
GhostCar.Instance.GetPosition(),
time * 10f
);
}
}
Any idea how I could address the issue? It's much smoother outside of the editor, but there's still a noticable jitter. I know it's not a framerate issue, since the profiler currently shows me at being above 250fps.
Answer by hexagonius · Feb 16, 2016 at 07:00 AM
I don't know how you picked your positions, but I think you should do this a little different. accumulate the time from the start. run through your positions until you find one that is smaller than the current time. subtract them to know how much you overshot it. also calculate the time between the picked position and the following. use lerp between those.
your problem is basically that you don't take the differences between the times from the race and the frame times you have during replay into account. frames can be little larger and smaller and never match during sessions
@hexagonius So I should record Time.time
, and not Time.smoothDeltaTime
? Then I take the difference between the current runs Time.time
, and the previous runs Time.time
?
I do think what you're suggesting would fix discrepancies between two runs, but would that correct the stutter I'm receiving from the lerp?
So, the Lerp should look something like this:
transform.position = Vector3.Lerp(previousPosition, SavedPosition, CurrentTime - PreviousRaceTime);
Your answer
Follow this Question
Related Questions
Frustrating Problem with Character Controller in FPS 0 Answers
How to Slerp / Lerp Rotation on a Single Axis? 0 Answers
Looking for the optimal smooth incremental movement method. 0 Answers
Unity network transform massive movement jitter jumps 0 Answers
Implementing a "flyer" game in with the old CardBoard Google sdk 2 Answers