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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question How to make child inherit parent's rotation at runtime?

Discussion in 'Scripting' started by AjaXI, Jan 8, 2023.

  1. AjaXI

    AjaXI

    Joined:
    Sep 13, 2020
    Posts:
    9
    So I'm attaching an object to another as it's child at runtime using this code:
    Code (CSharp):
    1. other.transform.SetParent(gameObject.transform);
    What happens is this:
    Imgur: The magic of the Internet

    I instead want the stick to rotate with the capsule.
    Thanks!
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    6,003
    Something else has to be effecting the rotation of the smaller object there. There's no constraints or anything on it?
     
    AjaXI and Bunny83 like this.
  3. AjaXI

    AjaXI

    Joined:
    Sep 13, 2020
    Posts:
    9
    That did it! I'm sorry for asking dumb question but I'm very new to Unity :)