0
if(wIsPressed){
    movement.x += sin((player.getRotation() * 3.141592654)/ 180) * .5; //accelerates ship at a rate of 0.5 ms^2
    movement.y -= cos((player.getRotation() * 3.141592654)/ 180) * .5; //accelerates ship at a rate of 0.5 ms^2

}
else if(abs(movement.x) > 0 || abs(movement.y) > 0){
    double angle = (atan2(movement.x, movement.y) * 3.141592654) / 180; //finds angle of current movement vector and converts fro radians to degrees


    movement.x -= sin((angle)) * 0.5; //slows down ship by 0.5 using current vector angle
    movement.y += cos((angle)) * 0.5; //slows down ship by 0.5 using current vector angle



}

basically, what happens after using this code is that my ship is pulled directly down to the bottom of the screen, and acts like the ground has gravity, and i dont understand what i am doing incorrectly

user3500457
  • 1
  • 1
  • 1
  • 1

1 Answers1

0

To elaborate on my comment:

You're not converting your angle to degrees properly. It should be:

double angle = atan2(movement.x, movement.y) * 180 / 3.141592654;

However, you're using this angle in another trig calculation, and the C++ trig functions expect radians, so you really shouldn't be converting this to degrees in the first place. Your else if statement could also be causing problems, because you're checking for an absolute value greater than 0. Try something like this:

float angle = atan2(movement.x, movement.y);
const float EPSILON = 0.01f;

if(!wIsPressed && abs(movement.x) > EPSILON) {
    movement.x -= sin(angle) * 0.5;
}
else {
    movement.x = 0;
}

if(!wIsPressed && abs(movement.y) > EPSILON) {
    movement.y += cos(angle) * 0.5;
}
else {
    movement.y = 0;
}
Julian
  • 1,688
  • 1
  • 12
  • 19
  • when i make this change, the ship moves to te bottom of the screen, then drifts back to the top again – user3500457 Nov 11 '14 at 05:44
  • It worked! the only thing i had to change was: movement.y += cos(angle) * 0.5; to movement.y -= cos(angle) * 0.5; and the epsilon value to 0.4f – user3500457 Nov 12 '14 at 07:49