Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Our response to Improbable’s blog post (and why you can keep working on your SpatialOS game). Read more here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Unity rotation

Discussion in 'Physics' started by Tempest74, Jan 10, 2019 at 8:12 PM.

  1. Tempest74

    Tempest74

    Joined:
    May 17, 2017
    Posts:
    91
    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:
    91
    everything I have tried so far add a weird movement on y axis or some weird rotation