I am trying to design a function that returns a Vector2D based on the angle difference of the camera compared to the forward vector of my character. I attached some images to explain better what I mean. (though I don’t know if angle difference is the right term or the right idea at all)
The yellow line is the camera while the orange line is meant to be the forward vector, I want to display the right sprite depending on where the camera lines on the “graph”. So if it is right over the forward vector it should return 0, -1 as x and y on the Vector2D and the plugin I have (PaperZD) will interpret this value and display the right sprite.
I am not very math savvy so does anyone have an idea for what I should be looking into to get closer to the solution?
Here I simply get the vector of the camera compared to the player character and normalize it. This gives me the x and y I was looking for and when outputted to the function PaperZD has to change the directionality the right sprite is displayed. But this solution makes it so the camera is the only thing that changes the sprite and I wanted it to have the forward vector in the equation so if the camera is opposite the vector it displays the back sprite and if on top it displays the front sprite and so on. I have the idea of rotating the vector2D based of the ACOS dot product of the forward vector of the camera and character but that seems to give me different results based on where the character is in the world. Anyone got ideas?
I honestly have no idea why it works but my brain just came up with the Atan2 idea randomly, I don’t actually understand what Atan2 is doing so if you know or can show me a visualization of it in action then feel free. I’ll leave this here for anyone in the future trying to make a game in similar style to us. Happy programming!