I am simulating cars driving through a road network given four columns of data time
, id
, x
and z
where a car with id id
is located at x,0,z
at time t
Here is a sample:
t id x z
957,1,-1.50,250.07
958,1,-1.50,232.39
959,1,-4.50,209.72
960,1,-4.50,193.05
961,1,-4.50,176.39
962,1,-4.50,159.72
963,1,-4.50,143.05
...
At the moment, I'm able to spawn cars and update their positions as time elapses and according to the data. I'm stuck on how to more realistically simulate car movement, instead of the car simply popping from point to point.
I am using Vector.Lerp
but it jump without consistent, smooth movement:
car.transform.position =
Vector3.Lerp(car.transform.position, nextPosition, Time.deltaTime);
At each second, I check the data above to find the coordinates of the car at the current second. Those coordinates are passed as nextPosition
into the above Lerp
function. This means that the car is 'Lerping' from point to point, every second.
How can I make the movement smoother? The position updates are every second and therefore the car needs to reach the next position in 1 second.