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. Dismiss Notice

Get euler angle from parent component

Discussion in 'Scripting' started by ml1985, Nov 20, 2014.

  1. ml1985

    ml1985

    Joined:
    Dec 29, 2013
    Posts:
    22
    Hi Guys

    I was wondering if it was possible to get the euler z angle of a parent object. Ideally I would like to rotate an object where its turn speed is a function (sine function) of the euler angle of its parent. The parent will also rotate independently.

    Any help would be greatly appreciated.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    Sure, transform.parent.rotation.eulerAngles... but maybe there's more to what you're trying to do than I understand?
     
  3. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    Good catch!
     
  5. ml1985

    ml1985

    Joined:
    Dec 29, 2013
    Posts:
    22
    Hi

    Thanks for the quick reply.

    I'm not doing anything complex at the moment I just want to test a method in principle.

    I have the parent cube rotating around the z axis at a constant speed.
    Now I have a second cube rotating around its own z axis again but I want it speed to be = parent speed * sin(z euler angle of parent).

    i tried transform.parent.eulerangles.z but its always 0 even when the parent is rotating about its z axis.
     
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,840
    Well, something's funny there. Try printing out transform.parent.gameObject.name. I think maybe it isn't what you think it is.