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

How to rotate globe around Y axis *and* up/down

Discussion in 'Scripting' started by AnthonyPaulO, Sep 3, 2012.

  1. AnthonyPaulO

    AnthonyPaulO

    Joined:
    Nov 5, 2010
    Posts:
    110
    I have a rotate script that allows me to spin a globe around it's Y axis. I also added the ability to rotate it up and down so that you can see the north and south poles, but locked so that you can't rotate it beyond a certain point, preventing the globe from going upside down. However, the up/down portion needs to be re-written because I completely missed a sore spot... My camera is situated so that it is looking straight at the equator of the globe; the camera is locked in place, only the globe can rotate. I can spin the globe along the Y axis, going either left or right, and all is well. However, if I try to rotate up or down I have a problem because I'm trying to rotate around the X axis *which is wrong*... what I really want is to rotate around an imaginary X-like axis that is always relative to my camera.

    To illustrate the problem, imagine someone facing you and you grab their nose. Pull their nose up and their head tilts back so you can see under their chin, pull their nose down and their head tilts towards you so you can see the top of their head. So far so good! Now turn him to the left or right 90 degrees so that you are looking at their profile. Now try to grab their ear and do the exact same thing. On a physical object like the human head I can easily do this, but I am unaware of an easy way in which I can do this in Unity and simply tell it to tilt towards or away from me... I need to give it both X and Z rotations, which is beyond my puny brain's abilities.

    Anyone have any pointers/links to articles/code?

    Thanks
     
  2. vagos21

    vagos21

    Joined:
    Sep 3, 2012
    Posts:
    18
    The way i would do it is this:

    keep my rotating globe with its script that rotates it around its Y axis, but then:
    Create an empty game object, make the globe a child of it, then do the "nose up down" rotation to that game object
    That's the technique used in cars with the wheels spinning and rotating and break calipers rotating without spinning too ;)
     
  3. AnthonyPaulO

    AnthonyPaulO

    Joined:
    Nov 5, 2010
    Posts:
    110
    omg... of course... same principle as ball and socket. doh! thx vagos, you're the man! :D

    .