V
V
Vladimir Borisov2020-02-27 00:04:16
C++ / C#
Vladimir Borisov, 2020-02-27 00:04:16

Can't figure out how to set up rotation in Unity?

Good day to all. I just started learning to write scripts in Unity and ran into a problem. There is a car that goes straight along the road and at the intersection it has to turn, without using any buttons.
I tried to implement it through If, so that when the coordinates of the car are equal to the coordinates of the trigger for the turn (I just made a cube so far), it turns and goes straight, but it does not turn. Maybe wrong somewhere. And if you tell me how to make a turn smoothly I will be very grateful.

void FixedUpdate() 
{
     Car22_1.transform.Translate(Vector3.forward * -Speed22 * Time.deltaTime);

           if (Car22_1.transform.position == TurnPoint22.transform.position)
            {
             Car22_1.transform.rotation = new Quaternion (0,180f,0,0);
             Car22_1.transform.Translate(Vector3.forward * -Speed22 * Time.deltaTime);
            }        
            Destroy(Car22_1.gameObject, 9f);     
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question