My game is supposed to have an object that changes it sprite depending on which way the mouse faces. programming this has become a challenge, because I want to calculate the angle relative to the center of the screen using the X axis.
To explain what I mean, pretend that under a sprite in the center of a screen is a protractor.
I want to measure the angle that's formed between the cursor and the center. If I use the X axis as a base, I should get an angle between 180° and -180°.
How would I achieve this? I've tried vector.angle(reference-vector)
, but that doesn't seem to give the desired result.
(reference-vector).angle(new Vector2(1.0, 0.0)/*x axis*/)
). \$\endgroup\$system.out.println()
, and I got what I thought at first to be a degree. However, as I examined closely, the value would change if I moved the cursor from right to left along the negative X axis, something it should only do on the positive X axis. I guess what I mean is that the value should have stayed 0, but decremented one time for every pixel the mouse moved. \$\endgroup\$