Search Unity

Rotation Constraint for only limiting rotation from parent?

Discussion in 'Editor & General Support' started by Josiah_Ironclad, May 23, 2020.

  1. Josiah_Ironclad

    Josiah_Ironclad

    Joined:
    Sep 24, 2019
    Posts:
    156
    Disclaimer: everywhere I say "spin" I mean rotation on the object's own axis.

    I've got a sun object that spins through a script using transform.Rotate (on its z axis), the planet children then orbit the sun using that rotation (through basic Unity parenting, no code involved). I'm also setting a spin speed for the planets through script. I'm trying to make it so that the rotation of the sun doesn't affect the rotation of the planets, but so I can still modify their rotation through code.

    Currently trying to do this with the Rotation Constraint component. But the only thing I can get out of it, is either the planets don't rotate at all, or they don't rotate through the code and only through the parent.

    This is my current setup:
    upload_2020-5-23_19-59-18.png

    Freezing z rotation axes freezes all rotation as long as the source's weight(?) is above 0. Unfreezing it just makes the planet spin relative to the sun (also as long as source's weight is above 0).

    Is it at all possible to achieve what I want, using this component? (making planet rotation be only affected through code while it's parented to the sun)?
     
    Pnvanol and RayanGhosh like this.
  2. Pnvanol

    Pnvanol

    Joined:
    Jan 11, 2016
    Posts:
    116
    A way I solved this is to use a source in the scene, that doesnt rotate. Then the child wont rotate with the parent either