Search Unity

Get entity Up normal from rotation

Discussion in 'Entity Component System' started by Michelle_Ca, May 19, 2020.

  1. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    is there a mathematical way to get entity up normal from rotation instead of using LocalToWorld.Value.c1 ?
     
    Last edited: May 19, 2020
  2. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Michelle_Ca likes this.
  3. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,270
    Code (CSharp):
    1. var up = math.mul(rotation, new float3(0f, 1f, 0f));
     
    Michelle_Ca likes this.
  4. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    Thank you very much guys !
    One more question please, Is there an alternative to Quaternion.Lerp in unity mathematics ?


     
  5. RecursiveEclipse

    RecursiveEclipse

    Joined:
    Sep 6, 2018
    Posts:
    298
    You might also consider LocalToWorld.Up, you don't mention why you need it the other way, but thought I'd mention.

    There is math.nlerp which takes quaternions and returns a normalized lerp.
     
    Michelle_Ca likes this.
  6. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    math.nlerp

    Code (CSharp):
    1. /// <summary>Returns the result of a normalized linear interpolation between two quaternions q1 and a2 using an interpolation parameter t.</summary>
    2. public static quaternion nlerp(quaternion q1, quaternion q2, float t)
    If you look at Quaternion.Lerp
    "Interpolates between a and b by t and normalizes the result afterwards."

    So they've just named it better this time.
     
    Michelle_Ca likes this.
  7. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    aw that's perfect many thanks !
     
  8. Michelle_Ca

    Michelle_Ca

    Joined:
    Aug 19, 2019
    Posts:
    113
    Because for some reason the value of LocalToWorld.Value.c1 change when changing NonUniformScale , It becomes smaller or larger depending on the scale.