Hi,
I am trying to create a system that allow to recreate player’s drive path. Vehicle is a rigidbody object with physic, “ghost” is simple transform that interpolates between positions and rotations from drivee path.
How it works now? I check every time step player’s vehicle position and rotation and save it in an array. It looks like this:
public void mark() {
time += Time.deltaTime;
if(time >= TIME_STEP) {
time = 0;
interpolations.Add(player.transform.position);
}
}
When I read array I try to interpolate between current position and destination point. Code looks like this:
void readMark() {
time += Time.deltaTime;
if(time >= TIME_STEP) {
time = 0;
if(index >= (interpolations.Length -1)) {
index = 0;
} else {
index++;
}
moveDirection = (interpolations[index] - transform.position).normalized;
velocity = ((interpolations[index] - transform.position).magnitude / TIME_STEP);
}
transform.position += moveDirection * (velocity * Time.deltaTime);
}
This code works… more or less. More, cus path is right, but less, cus you can notice juttering while moving. Any ideas how it should be done without annoying jittering?