Friday 9 August 2013

Object wont move based on angle given?

Object wont move based on angle given?

So I've been trying to make an object move based on two speeds that it
creates using atan(). But every test results in the same movement of going
straight up.
So I decided to take that out and replace it with inputted angles which
oddly does only work for the the four angles 90 180 270 0.
I'm not sure why it only goes for only those for directions here's my code:
public void update() {
updateDir();
move();
}
public void updateDir(){
dir = Math.atan(spdY/spdX);
dir =20; //I know this is here it was used to test if it will actually
change
dir = dir * Math.PI / 180.0;
System.out.println("dir: " + dir);
}
public void move() {
x += (spd*Math.cos(dir));
y -= (spd * Math.sin(dir));
}
Any reason why it only goes in 4 directions?

No comments:

Post a Comment