# How to correct this issue with a top-down aiming angle in Unity - 2D?

I'm trying to build my first project and I'd like some input for a math correction. The game is a top down 2D shooter, a bit like the iconic "chaos engine" from SNES.

The issue is that either the player (controller by mouse position) or the enemy don't aim accurately enough on certain angles. I'm using a formula that translates the coordinates of the target point into a rotation, so the sprite faces the target. The bullets are always shot straight. The problem is that they miss the target in certain orientations... it doesn't seem accurate enough. I've been looking for a best approach but so far I haven't found any. Can anyone help? Thank you in advance!

To rotate the enemy I'm using this:

 Vector3 currentPosition = transform.position;

Vector3 nextPosition = target.transform.position;

Vector3 directionOfTravel = nextPosition - currentPosition;

float angle = (Mathf.Atan2(directionOfTravel.y, directionOfTravel.x) * Mathf.Rad2Deg) - 90;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);


• Where is (0,0) on your sprite? If it isn't exactly in the center of your sprite then your rotation will be off. Are you sure the red line is really starting from the center of the model and not the right edge? – Dunk Jul 14 '16 at 23:01
• you gave me the good input! actually it wasnt 0.0.0, but I had to place the shotspawn at the exact position of the gun. now its fine! merci cher ami! – Denis Taquet Jul 23 '16 at 0:31
• Post that as an answer @Dunk or yourself Denis. – Draco18s no longer trusts SE Aug 19 '19 at 4:03

 float step = speed * Time.deltaTime;