- Home /
How do I make one GameObject Point Towards another GameObject in 2D?
Hi, I have created two game objects in my scene and I am trying to make one point towards the other. I understand Unity has a built in transform.LookAt() function but this function does not work in 2D. I understand this has been asked many times before and I have tried everything but it still doesn't work (probably because those solutions I have been looking at are only compatible with older versions of Unity). If anybody knows how to fix this it would be much appreciated if you could let me know how.
Many Thanks,
Tommy Eaves
Comment
Best Answer
Answer by jmgek · Dec 08, 2015 at 12:30 AM
Quaternion rotation = Quaternion.LookRotation (Target.transform.position - transform.position, transform.TransformDirection(Vector3.up));
transform.rotation = new Quaternion(0, 0, rotation.z, rotation.w);