Search Unity

How to set another default rotation of gameobject ?

Discussion in 'Physics' started by massiwo, Mar 26, 2015.

  1. massiwo

    massiwo

    Joined:
    Dec 26, 2014
    Posts:
    12
    Hello,

    I would like to set an other default rotation on a gameobject.
    Actually, my gameobject (a toy) at the rotation 0,0,0 is lying down, but i want her to be standing at the rotation 0,0,0 because my script "look at', lie down the toy.

    My script :
    Code (CSharp):
    1. Transform target = GameObject.FindWithTag("Player").transform;
    2. Vector3 lookPos = target.position - transform.position;
    3. lookPos.y = 0;
    4. Quaternion rotation = Quaternion.LookRotation(lookPos);
    5. transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 2f);
    Thanks
     
    Last edited: Mar 26, 2015
  2. Nanako

    Nanako

    Joined:
    Sep 24, 2014
    Posts:
    1,047
    it sounds like an issue with the mesh to be honest. Whatever you think forward is, is not what the mesh's forward is.

    Firstly, i'd say you should have the object inside some parent object, that's my standard procedure. Pretty much anything containing a mesh should be a child of something else, not the world. Even if just an empty parent. And i put all the scripts, and functional components, on that parent. It allows models to be easily swapped out without affecting functionality. So anyways get it inside a parent.

    Then try setting a rotation on your visual object, and see how that affects the pointing. In this case you will want to run the code on its parent, not on the mesh object itself. So move all your scripts to the parent