Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity rotation

Discussion in 'Physics' started by Tempest74, Jan 10, 2019.

  1. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    133
    Code (CSharp):
    1. Quaternion targetRotation = Quaternion.LookRotation(path.lookPoints[pathIndex] - transform.position);
    2.                     transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSpeed);
    3.                     transform.Translate(Vector3.right * speed * Time.deltaTime,Space.Self)
    My piece of code is above. I am following a tutorial for a 3d pathfinding script, but I use it for a 2d game. Everything worked fine until now, but I got in some mathematical trouble, i think it is good to say. My gameobjects are places into a xy axis coordinate. I want to face them one toward another, so I tried using Quaternion.LookRotation, and it changed the rotation on x and y axis but apparently i need to rotate it on z axis (for no reason known to me). Any help?
     
  2. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    133
    everything I have tried so far add a weird movement on y axis or some weird rotation