Reputation: 108
I am trying to make an object look at the player and it is working as intended but for some reason it is facing the wrong direction. I have drawn an example of what is happening in my game. As you can see for some reason the pivot is facing the wrong direction.
My code:
void Update()
{
var dir = player.transform.position - transform.position;
var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
Upvotes: 0
Views: 171
Reputation: 108
I managed to figure it out by deducting -180 to the angle :)
Upvotes: 1