I’m currently working on a top down pixel art game and I’m trying to make the attack animation play based on where the mouse is (e.g. if the mouse is above the player the attack up animation will play). To achieve this, I’m trying to convert the mouse position on screen to degrees so that I can freely define each direction. I don’t want to make quadrant instead because I plan on adding in 8 attack directions. I’ve been trouble shooting this for a little bit and I can’t seem to get the angle to not be influenced by how far the mouse is away from the center of the screen (where my character is). I’m pretty new to unreal so I’m assuming my incompetence is playing a big role. Thus far, I’ve used two blueprint setups which I will be attaching below. Is there a better way to set this up or am I going wrong somewhere?
EDIT: I just realized that atan is inverse tangent and what I needed to have been using originally was inverse cosine. Using the inverse cosine function along with rewriting some of my code I was able to get a usable half circle. However, the circle does not go past 180 nor does it have negative values. This means I won’t be able to make an attack down input. Is there a way to make the circle go to 360 degrees or is this something that’s built into unreal?
If you want a range of 0 to 360, you’d use atan or atan2 as you were doing before. Or do a combination of acos and asin to tell you different parts of the angle information.
You look like you’re on the right path with the first image: creating a vector from the center of the screen to the mouse cursor, normalize it, pass that into atan2.
Not really sure what you’re doing with the extra vector up to the middle of the screen, that will always be a constant value that you would just factor in as a constant offset in the rotation.