Matthew Scicluna
Matthew Scicluna

Reputation: 108

Unity2D: Look at object is flipping my object

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.

enter image description here

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

Answers (1)

Matthew Scicluna
Matthew Scicluna

Reputation: 108

I managed to figure it out by deducting -180 to the angle :)

Upvotes: 1

Related Questions