# How can I find the direction a sprite is moving?

I’m trying to get the direction a sprite is moving (up, down, left, right). My current approach is to get the x and y coordinates of the target and the sprite (the sprite is the thing that I’m trying to get the direction of), and then have booleans be true/false based on the the values of the x/y coordinates (if they are greater than, less than, etc.). I’m not trying to rotate the sprite or change anything about how it’s drawn, just find the direction that it’s moving in. This is what I’m currently trying (this is more of a general idea of what I’m doing, and is pretty rough):

``if (Target.Position.X < Position.X && Target.Position.Y < Position.Y - 500) {     IsFacingUp = false;     IsFacingDown = false;     IsFacingLeft = true;     IsFacingRight = false; } else if (Target.Position.X < Position.X && Target.Position.Y > Position.Y + 500) {     IsFacingUp = false;     IsFacingDown = false;     IsFacingLeft = true;     IsFacingRight = false; } else if (Target.Position.X > Position.X && Target.Position.Y < Position.Y - 500) {     IsFacingUp = false;     IsFacingDown = false;     IsFacingLeft = false;     IsFacingRight = true; } else if (Target.Position.X > Position.X && Target.Position.Y > Position.Y + 500) {     IsFacingUp = false;     IsFacingDown = false;     IsFacingLeft = false;     IsFacingRight = true; } else if (Target.Position.Y <= Position.Y - 500) {     IsFacingUp = true;     IsFacingDown = false;     IsFacingLeft = false;     IsFacingRight = false; } else if (Target.Position.Y >= Position.Y + 500) {     IsFacingUp = false;     IsFacingDown = true;     IsFacingLeft = false;     IsFacingRight = false; } ``