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

Quaternion.Slerp except (0,0,0) is parent's object's rotation, or equivalent?

Discussion in 'Scripting' started by Th0masThe0bvious, May 17, 2021.

  1. Th0masThe0bvious

    Th0masThe0bvious

    Joined:
    Aug 22, 2018
    Posts:
    80
    Hello there,

    I was using this tutorial
    to make two child objects rotate to a set angle; we can get into more details about the specifics if needed, but for now suffice it to say that there are two child objects that I need to rotate. I got things working pretty well in that tutorial except for one thing: It's coordinates are all absolute. This means that if the parent object's rotation ever changes--and it does, in our game--then it will move independently of the child objects and they will be left in a weird spot.

    So my question is what I could do to accomplish the same thing, except instead of a global 0,0,0 rotation being the base, that is the parent object's rotation? I had assumed maybe I could do this via a quaternion that sets itself to the parent's rotation every step, and this actually works as the child object's local "zero" position but doing any math with it doesn't seem allowed. In other words, if there's a way to code quaternions as essentially "parent object's rotation minus 24 degrees", I haven't found it.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    I didn't watch the tutorial but the gist of it would be:

    Do exactly what's suggested in the tutorial, except work exclusively with
    transform.localRotation
    instead of
    transform.rotation
     
  3. Th0masThe0bvious

    Th0masThe0bvious

    Joined:
    Aug 22, 2018
    Posts:
    80
    Oh thank you; that worked perfectly!

    Also that cat in your avatar is very cute, and I own one who looks very similar.
     
  4. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    Don't encourage him. He's a monster and he must be stopped.
    My condolences.
     
    StarManta likes this.