I'm pretty new to java and I am having some major trouble doing what I thought would be fairly simple. Anyway, so far I have a character object that I want to only move at a max speed of 5 in ANY direction, because as we know if I set the x velocity and the y velocity to a max of 5 then it can go faster at an angle because of the pythagorean theorem. So in my KeyInput class I set up a method that controls the angle of my player, and that is working perfectly fine.
Anyway, I thought I knew trigonometry but now I realize I don't. The angle is set to be out of 360, and when it goes over 360 I subtract 360 from the value and that is the new angle. When I hold down an arrow key and the forward button which makes the player initiate motion, I get a circle but it spirals towards the top left. Help?
Here is my x velocity handler, the y is just the same but the sines are flipped to cosines and the cosines are flipped to sines:
public double handleAngledXVelocity(double tempAngle) {
double handledvelX;
if (movingForward == true) {
if (tempAngle > 270.0 && tempAngle <= 360.0) {
tempAngle = tempAngle - 270.0;
handledvelX = (-5 * Math.cos(tempAngle * Math.PI / 180));
} else if (tempAngle > 180.0 && tempAngle <= 270.0) {
tempAngle = tempAngle - 180.0;
handledvelX = (-5 * Math.sin(tempAngle * Math.PI / 180));
} else if (tempAngle > 90.0 && tempAngle <= 180.0) {
tempAngle = tempAngle - 90.0;
handledvelX = (5 * Math.cos(tempAngle * Math.PI / 180));
} else {
handledvelX = (5 * Math.sin(tempAngle * Math.PI / 180));
}
} else {
handledvelX = 0.0;
}
return handledvelX;
}