Godot Version
4.6.2
Question
I noticed some other posts about this and looked through them, but none of them quite worked for me. I’m not great with math so I was a bit confused, even after testing multiple ways I couldn’t get this to work.
I have this sprite sheet with 8 directions, where the sprite displayed corresponds to where my mouse is on-screen (if its near or at the top of the screen relative to where the sprite is, show the back sprite, if the mouse is at an angle to the left, show the angled left sprite, etc.) These aren’t animated/aren’t meant to be an animation, just showing a different sprite based off of where my mouse is around it.
I noticed in two instances people would have a “direction vector” variable that was a Vector.ZERO, given a string name based off of where the mouse position is, but I’m unsure how they actually get the string to change something. Any help would be appreciated to understand how this could be done!

Since you already have an idea of what you want, let’s make a plan:
- Find out the mouse position (usually a vector)
- Find out the sprite position (usually a vector)
- Make sure both are in the same coordinate space
- Depending on both positions, you want 8 different outcomes, one for each direction
- Once you know the direction, find out the respective sprite
- Change the sprite accordingly
Some of these can be implemented in different ways. In step 4, you would usually want to compute a relation between both positions, which often boils down to a direction vector or an angle (that can be derived from the direction vector). This is quite simple math, but Godot also has built-in functions for these, e.g. vector1.direction_to(vector2)
If you’re stuck, try debugging or printing the current values and see if they match up with your expectation
This has been answered many times here. I myself answered it several times. There are also many tutorials out there. Here’s one
https://kidscancode.org/godot_recipes/4.x/2d/8_direction/