I have a problem with my code in Android. I am using this to moving a ball. If the degree is 90 it should move to the right, if the degree is 180 it should move down etc.
This is the code I have done.
int degrees=180;
int bollspeed=4;
bollX += bollspeed*Math.cos(Math.toRadians(degrees));
bollY += bollspeed*Math.sin(Math.toRadians(degrees));
The problem is that when the ball should move 90 degrees it moves 180, and when it should move 180 degrees it moves 270. I have tested all I could come to think... Can anyone see any error in my code or have a expanation I would be really glad. Thanks
How about Math.toRadians(degrees-90) ? When using polar coordinates, 0 degree is supposed to be at 3 o'clock, not at 12.
Why not subtract 90 degrees then?
bollX += bollspeed*Math.cos(Math.toRadians(degrees-90));
bollY += bollspeed*Math.sin(Math.toRadians(degrees-90));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With