So in this script I move a car in forward and backwards directions and keeping the speed at a certain range.
void MoveCar(float direction)
{
Vector3 localVelo= transform.InverseTransformDirection(rb.velocity);
if (localVelo.z < maxSpeed && localVelo.z > maxBackSpeed)
rb.AddRelativeForce(Vector3.forward * speed * direction);
}
I call it in FixedUpdate. If the direction parameter is 1 it goes forward, -1 it goes backwards. However the problem is that it does not go in a straight line and the Y axis ever so slightly increases as the car moves. The object itself is rotated 90 degrees on the Y axis for level design purposes. Is there a way to fix this? Thanks in advance guys