Update Coordinates Based On Angle And Speed
Solution 1:
Your problem comes from the fact that :
int x = 0;
x = x + 0.5; // rounding down : x == 0
x = x + 0.5; // rounding down : x == 0
You need a float variable to memorize the position.
float x = 0;
x = x + 0.5; // x == 0.5
worldX = (int)x; // worldX == 0
x = x + 0.5; // x == 1
worldX = (int)x; // worldX == 1
That will solve the problem.
Solution 2:
Not sure if this would work, but try multiplying the angle by PI before dividing by 180 when converting the angle to radians.
double radians = (Math.PI * user.fAngle) / 180;
EDIT:
I just noticed that worldX and worldY have type int. You should change their type to double, since the displacements are most likely fractional.
Solution 3:
"...let's say north is 0. If I'm moving at an angle of 5, the worldY variable should be changing a lot, but worldX should be changing a little. This is not happening."
The formulas you gave for the X and Y motions actually assume that north is 90 degrees.
In trigonometry, an angle of 0 degrees is along the +X axis, which would correspond to due east on a map. Also, in trigonometry, increasing the angle moves it counter-clockwise around the origin. If you want your angles to act like compass headings, with north at 0 degrees, east at 90 degrees, and so on, you should define radians
like this:
double radians = (Math.PI / 180) * ( 90.0 - user.fAngle);
Post a Comment for "Update Coordinates Based On Angle And Speed"