# Rotate GameObject around point in 2D Top-Down

I have an enemy that has an attack AOE (area of effect, it is a trigger polygon collider) in which any objects will get damaged when the enemy attacks. I want the AOE to rotate towards the target (the player) around the enemy, but I can’t figure out how to do so. (I don’t want the enemy itself to rotate because it would ruin the pixel art sprites)

Here’s what I’ve tried so far:

``````float _zRotation = 0f;
if (player.position.x >= trans.position.x)
{
_zRotation = Mathf.Asin(player.position.normalized.y - trans.position.normalized.y) * Mathf.Rad2Deg;
}

else
{
if (player.position.y >= trans.position.y)
{
_zRotation = 180f - (Mathf.Asin(player.position.normalized.y - trans.position.normalized.y) * Mathf.Rad2Deg);
}

else
{
_zRotation = (Mathf.Asin(player.position.normalized.y - trans.position.normalized.y) * Mathf.Rad2Deg) + 180f;
}
}

attackAOE.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
attackAOE.transform.Rotate(Vector3.forward, _zRotation);
``````

I’ve taken this from my code that rotates a bullet in the direction of the mouse when it gets shot, which is this portion, made with my (rather limited) knowledge of trig:

``````Vector2 _mouseDir = Camera.main.ScreenToWorldPoint(_mouseScreenPos) - trans.position;
_mouseDir.Normalize();

float _zRotation;
if (_mouseScreenPos.x >= Screen.width / 2)
{
}

else
{
if (_mouseScreenPos.y >= Screen.height / 2)
{
_zRotation = 90 - (Mathf.Asin(_mouseDir.y) * Mathf.Rad2Deg) + 90f;
}

else
{
_zRotation = (Mathf.Asin(-_mouseDir.y) * Mathf.Rad2Deg) + 180f;
}
}
``````

With 2d stuff you need to rotate around the axis going into the screen, so the z axis usually. Can easily do this by just getting the angle between some reference direction (your sprites normal orientation) and the direction to the player.

Usually this reference direction is Vector2/3.up, and you can get the angle with Vector3.SignedAngle. You can make the rotation with `Quatenion.AngleAxis`, and just assign that to your game object.

My new code is:

``````float _zRotation = Vector3.SignedAngle(attackAOE.transform.position - trans.position, player.position - trans.position, Vector3.up);
attackAOE.transform.rotation = Quaternion.AngleAxis(_zRotation, Vector3.up);
``````

This doesn’t work though as it rotates the attack AOE around the y-axis.

So, I changed the code to this, using Vector3.forward:

``````float _zRotation = Vector3.SignedAngle(attackAOE.transform.position - trans.position, player.position - trans.position, Vector3.forward);
]attackAOE.transform.rotation = Quaternion.AngleAxis(_zRotation, Vector3.forward);
``````

But it still doesn’t work correctly