Help with Snapping

Hello, when the player moves the cursor, I’m trying to make it so that the ActionMarker snaps either only above, below, to the left or right of the player.

The snapshot I’ve attached to this post is what I have for the script. When I test the game, the ActionMarker only snaps to the left and right of the player. I don’t understand why the ActionMarker doesn’t snap above and below the player? Can someone explain this to me, and what I should do to fix/achieve this goal?

This is the result when I test the game:


Because you are placing the ActionMarker based on the mouse X position to the player after you’ve done it for the y position. Unless the mouse X position is exactly the same as the player, it overrides the position based on the Y differences.

You’ll need to determine which difference is the greatest; that along the Y axis or that along the X axis. And then place the action marker based on that result.

Hint - use something like this pseudo code: abs(mouseX - playerX) > abs(mouseY - playerY) to move it in the X axis. And similar code to move it in the Y axis.

You could use the bounding box values of the player instead of the center then you can change just the matching x or y not both.

If cursorX() < player.BoundingBoxLeft() then set the x of ActionMarker to player.CenterX() - 20

And then the same for right and then set the Y with top and bottom.