Java :moving ball with angle ?
Posted
by Meko
on Stack Overflow
See other posts from Stack Overflow
or by Meko
Published on 2010-04-29T21:31:57Z
Indexed on
2010/04/29
21:57 UTC
Read the original article
Hit count: 484
java
Hi all.I am started to learn game physics and I am trying to move ball with an angle.But it does not change its angle .Java coordinate sydstem is a little different and i think my problem is there.Here my codes
this is for calculating x and y speed
scale_X= Math.sin(angle);
scale_Y=Math.cos(angle);
velosity_X=(speed*scale_X);
velosity_Y=(speed*scale_Y);
This is for moving ball in run() function
ball.posX =ball.posX+(int)velosity_X;
ball.posY=ball.posY+(int)velosity_Y;
I used (int)velosity_X and (int)velosity_Y because in ball class I draw object
g.drawOval(posX, posX, width, height);
and here g.drawOval requares int.I dont know is it problem or not. Also if I use angle 30 it goes +X and +Y but if I use angle 35 it goes -X and -Y. I didnot figure out how work coordinate system on java.
© Stack Overflow or respective owner