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

Question Trouble aligning transforms

Discussion in 'Scripting' started by The-Magman, Mar 29, 2021.

  1. The-Magman

    The-Magman

    Joined:
    Mar 16, 2013
    Posts:
    2
    Hi whenever a player picks up a object(missionScroll in this case) in my game I make it a child of the hand(attach) object.
    To get the right rotation and position of the object in relation to it's parent (hand) I have added a empty with the desired position and rotation offset the object should use.
    .

    insta.gif

    How can I set the transform of missionScroll so that it aligns with the attachpoint from code?

    Thank you for reading.
     
  2. Kona

    Kona

    Joined:
    Oct 13, 2010
    Posts:
    208
    Instead of having the AttachPoint as a child of the MissionScroll, make the AttachPoint a child of LeftHand Controller. Will make it easier 'cause then you can simply copy the transform's properties over to the MissionScroll like so:

    Code (CSharp):
    1. Transform missionScroll;
    2. Transform attachPoint;
    3.  
    4. missionScroll.SetPositionAndRotation( attachPoint.position, attachPoint.rotation );
     
  3. The-Magman

    The-Magman

    Joined:
    Mar 16, 2013
    Posts:
    2
    Thank you for your response, I would like to keep the attachpoint on the object so I can configure it for each object instead of the hand object holding that data (and all other objects).