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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

how to make the child always look down

Discussion in 'Scripting' started by Trild123787898, Nov 5, 2021.

  1. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    how to close so that the child always looks down, even if the parent makes any movement to the right, left, turn, the child must always look down
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    Don't make it a child, make it a sibling.
     
  3. HellGate94

    HellGate94

    Joined:
    Sep 21, 2017
    Posts:
    132
    make the parent tell him he is a total failure. it will never look up again

    on a real note you could just make a script that sets the rotation inside LateUpdate
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    It does depend on what you want but you can also use simple Transform Constraint components to save you doing the math here unless of course your question is about how to do the math.

    Lots of ways of doing it. You could add a Rotation Constraint to the child, add another GameObject with the Rotation you desire (or use an existing one such as a ground object) as a Source Object, Activate the Constraint. Press play and modify the parent. The child will be constrained in whatever axis you want.

    https://gyazo.com/448bb73ae982fd341ba0effaed9fbe5a

    I'm not an expert on using these constraints however.
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,204
    Code (csharp):
    1. child.transform.forward = Vector3.down;
    Do that after whatever moves the parent in done moving it.
     
    MelvMay likes this.
  6. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    thanks, but how to freeze the rotation of the child along the Y axis, I just rotate the riddle along this axis, and the child turns behind it
     
  7. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,204
    If it's starting with the correct orientation, you can also do:

    Code (csharp):
    1.  
    2. Quaternion childRotation;
    3. void Awake() {
    4.     childRotation = child.rotation;
    5. }
    6.  
    7. // later:
    8. child.rotation = childRotation;
     
    Trild123787898 likes this.
  8. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    thanks