Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Transform.lookAt doesn't work properly. pivot problem. (SOLVED)

Discussion in 'Physics' started by sush333, Feb 23, 2015.

  1. sush333

    sush333

    Joined:
    Jan 26, 2015
    Posts:
    32
    I want an enemy ship to face towards the player but i get an unusual rotation in the enemy ship when i use this function on the enemy ship. my enemy ship pivot is far away from it's mesh.

    IS THERE ANY ALTERNATIVE FUNCTION OR METHOD to point my ship z towards a moving player ship??

    please help!
     
  2. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Is it not possible for you to change your ship's pivot to be on the mesh?

    The other solution is to have your ship's mesh be a child to a GameObject which for all intents and purposes will be the "real" ship. Offset the GameObject with the mesh by the opposite offset of its pivot, then use Transform.LookAt on the parent.
     
  3. sush333

    sush333

    Joined:
    Jan 26, 2015
    Posts:
    32
    I searched a lot to change the pivot but couldn't find any way to change that in unity. (Tell me if you got any way) how would making the enemy a child of the player make it point towards the playrr aalways . And that would create thousands more problema for me. I am sure that's not. A convenient way. I need to change the pivot posion or if there is some other way then it would be great.
     
  4. sush333

    sush333

    Joined:
    Jan 26, 2015
    Posts:
    32
    Thanks for your help. I solved it by placing the object in An empty game object so that the empty object becomes the parent, and now the lookAt function works properly.