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

Confused about Inspector values and what is reported by Debug

Discussion in 'Getting Started' started by Bill_Martini, Jan 20, 2017.

  1. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    I'm trying to set an objects speed when traversing slopes. I want a 1960's VW bus style physics (ie. you can go as fast as you can down hill, but uphill is a strain and a good running start helps). I used the players rotation to see if it was going uphill or down. I started to get odd velocity numbers so I displayed rotational values in a debug.log. These didn't correspond to the values in the inspector. The Inspector's value for a rotation of one axis is 122.792 but the debug.log shows -0.2603793 for both local and world. I don't think local and world should be the same and one of them at lease should be the same value as what is shown in the inspector. Why am I getting what looks like normalized values? Am I missing something obvious?

    Code (csharp):
    1.  
    2. Debug.Log ("World = " + model.transform.rotation.z.ToString () + "  Local = " + model.transform.localRotation.z.ToString ());
    3.  
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,512
    If you look at the API for localRotation, you'll see it returns a Quaterion. The Inspector communicates rotation values in degrees, like we're used to dealing with, but quaternions are useful in various mathematical operations. You can get the euler angle by doing:
    Code (CSharp):
    1. model.transform.localRotation.eulerAngles.z
     
    Kiwasi and JoeStrout like this.
  3. Bill_Martini

    Bill_Martini

    Joined:
    Apr 19, 2016
    Posts:
    445
    And you would be correct sir! I knew something was wrong as the world and local should not have been the same. I walked by the obvious and started digging for complicated reasons. I do have my bad days.

    Thanks for the course correction.