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
}基本上,使用这段代码后,我的船会被直接拉到屏幕底部,就像地面有重力一样,我不明白我在做什么不对。
发布于 2014-11-11 05:36:29
关于我的评论,我要详细说明:
你没有正确地把你的角度转换成度。它应该是:
double angle = atan2(movement.x, movement.y) * 180 / 3.141592654;但是,您在另一个trig计算中使用了这个角度,而C++ trig函数期望的是弧度,所以您不应该首先将其转换为度。如果else语句也可能导致问题,则需要检查大于0的绝对值。试着做这样的事情:
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;
}https://stackoverflow.com/questions/26857901
复制相似问题