- Home /
2D Rotate object so y axis faces other object
I have a 2D missile. I need to rotate the missile so that the top/tip of the missile is facing the player. The player is the alien ship. The missile is the blue and red thing.
Here is an image below of the current situation.
I need to rotate around the z axis to get the top to point towards the alien but when ever I use transform.LookAt or quaternion.LookRotation it always makes the flat side face the alien, not the top/tip of the missile
Answer by Spinnernicholas · Dec 18, 2013 at 11:44 PM
Do this:
transform.LookAt(transform.position + new Vector3(0,0,1), target);
You can still use the lookat function, you always want the sprite to "lookat" the camera(along the z axis for xy plane). But, you angle it so that the up vector points at your target.
This is assuming that the top of the missile is the top of the sprite.
Code above worked but slight modification. Thanks
transform.LookAt(transform.position + new Vector3(0,0,1), target.transform.position - transform.position)
Assets/scripts/bullet.js(95,21): BCE0023: No appropriate version of 'UnityEngine.Transform.LookAt' for the argument list '(UnityEngine.Vector3, UnityEngine.Transform)' was found.
idk how can I make my bullet look at the smoke co$$anonymous$$g out from its back (clone prefab)