Answer the question
In order to leave comments, you need to log in
How to make turns smoother?
Turning at the touch of a button is instantaneous, which is logical, but how to make it smooth? So that the car turns not in one frame, but in one second? Inserting Time.deltaTime as the 2nd argument to the method in the Rotate method will be incorrect, because then the rotation will simply be small, not smooth.
public class CarMovement : MonoBehaviour
{
public float speed;
public float turnAngle;
private void Update()
{
transform.Translate(Vector3.forward * speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.A))
{
CarTurnLeft();
}
else if (Input.GetKeyDown(KeyCode.D))
{
CarTurnRight();
}
}
private void CarTurnRight()
{
transform.Rotate(Vector3.up, turnAngle);
}
private void CarTurnLeft()
{
transform.Rotate(Vector3.up, -turnAngle);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question