Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Whats the difference between these two quaternions ?

Discussion in 'Scripting' started by tibor698, Oct 9, 2013.

  1. tibor698

    tibor698

    Joined:
    Nov 26, 2012
    Posts:
    84
    Whats the difference between
    Code (csharp):
    1. Quaternion.AngleAxis(0, Vector3.up)
    and
    Code (csharp):
    1. Quaternion.AngleAxis(15, Vector3(0, 0, 0))
    Are they both valid and what happens if they are not ?
     
  2. GoRiLLa

    GoRiLLa

    Joined:
    Oct 8, 2013
    Posts:
    14
    Both are valid, but they don't really do anything.

    The first one rotates 0 degrees around the up vector.
    Vector3.up is the same as writing Vector3(0,1,0) btw;

    The second one rotates 15 degrees around the zero vector, which also is the same as no rotation at all
     
  3. tibor698

    tibor698

    Joined:
    Nov 26, 2012
    Posts:
    84
    I ask because I want to rotate and move my object toward some other object. But I don't want to use LookAt() becase I want to rotate smoothly.
    This code works but when direction changes to next object (waypoint) my object continues just forward with no change in direction, or sometime it does but not towards next object but in some random direction.

    This is my code:
    Code (csharp):
    1.         distance = waypoints[next].position - transform.position;
    2.         if(distance.magnitude < epsilon)
    3.             next = PickWaypoint(next);
    4.        
    5.         rotationDir = Vector3.Cross(transform.forward, distance.normalized);
    6.         rotationDir.Normalize();
    7.         angle = Vector3.Angle(transform.forward, distance.normalized);
    8.         rotation *= Quaternion.AngleAxis(angle*Time.deltaTime, rotationDir);
    9.        
    10.         transform.rotation = Quaternion.Slerp(transform.rotation, rotation, damping*Time.deltaTime);
    11.         transform.Translate(new Vector3(0.0f, 0.0f, 1.0f)*Time.deltaTime*speed);