Search Unity

confused about position and rotation after parenting;

Discussion in 'Editor & General Support' started by steveh2112, Feb 16, 2020.

  1. steveh2112

    steveh2112

    Joined:
    Aug 30, 2015
    Posts:
    314
    i am trying to place something as a child of an object and set its position and rotation to that of the parent, but it refuses to work. you can see in the screen shot, the knife should be in the holster
    upload_2020-2-16_19-57-13.png

    here is the code
    Code (CSharp):
    1. knife.parent = _Holster;
    2.         knife.position = Vector3.zero;  //_Holster.transform.position; // Vector3.zero;
    3.         knife.eulerAngles = Vector3.zero;  //_Holster.transform.rotation; //Quaternion.identity;
    if you look at the inspector, the position and rotation are not zero, even through i have that in the script.

    if i manually set pos and rot to 0 in the inspector, like this
    upload_2020-2-16_20-0-7.png
    its perfect.

    i've tried several options, setting pos and rot to same as the parent after parenting, setting pos and rot to same as the parent before parenting, nothing seems to work. any ideas how to do this simple thing.

    by the way, i know in the models the position and rotation are all lined up to fit perfectly without moving or rotating because i set it up in blender.
    thx
     

    Attached Files:

  2. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    You want to use localPosition and localEulerAngles, otherwise you are setting the knife to be the global zero.

    The inspector modifies local position/angles.
     
    steveh2112 likes this.
  3. steveh2112

    steveh2112

    Joined:
    Aug 30, 2015
    Posts:
    314
    that did it, thanks