Game Maker WASD 和方向键顺畅旋转?

Game Maker WASD and arrow keys smooth rotation?

如何使用 WASD 或箭头键进行平滑旋转?我看到了一些例子,但他们都使用鼠标。我当然想使用 WASD 或箭头键。我真的希望有人能帮助我。

到目前为止,这是我的代码。

// You can write your code in this editor
if(keyboard_check_pressed(ord("W"))) or (keyboard_check_pressed(vk_up)){
    speed = sailSpeed;
    image_speed = 1;
}
if(keyboard_check_released(ord("W"))) or (keyboard_check_released(vk_up)){
    speed = 0;
    image_speed = 0;
    image_index = 0;
}
if(keyboard_check_pressed(ord("D"))) or keyboard_check_pressed(vk_right){
    direction -= 45;
}
if(keyboard_check_pressed(ord("A"))) or keyboard_check_pressed(vk_left){
    direction += 45;
}

if(direction == 0) or (direction == 360) or (direction == -360){
    sprite_index = sprPlayerShipRight;
}
if(direction == 45) or (direction == -315){
    sprite_index = sprPlayerShipUpRight;
}
if(direction == 90) or (direction == -270){
    sprite_index = sprPlayerShipUp;
}
if(direction == 135) or (direction == -225){
    sprite_index = sprPlayerShipUpLeft;
}
if(direction == 180) or (direction == -180){
    sprite_index = sprPlayerShipLeft;
}
if(direction == 225) or (direction == -135){
    sprite_index = sprPlayerShipDownLeft;
}
if(direction == 270) or (direction == -90){
    sprite_index = sprPlayerShipDown;
}
if(direction == 315) or (direction == -45){
    sprite_index = sprPlayerShipDownRight;
}

这是您想要的吗?

directionHorizontal = (keyboard_check(ord("D")) - keyboard_check(ord("A"));
directionVertical = (keyboard_check(ord("S")) - keyboard_check(ord("W"));
directionMoving = point_direction(0, 0, directionHorizontal, directionMoving);
var directionDifference = angle_difference(direction , directionMoving );
direction -= min(abs(directionDifference ), 10) * sign(directionDifference);

编辑:抱歉,我看错了。听起来你是在对转弯速度进行加速和减速之后。我会做的是:

将 approach() 添加到您的项目中: https://pastebin.com/7gzJTLKj

在创建事件中初始化这些变量:

turningSpeed = 0;
turningSpeedMax = 15;
turningSpeedIncrement = 1;

而在步进事件中,你可以这样:

turningDirection = (keyboard_check(ord("D")) - keyboard_check(ord("A")));
turningSpeed = approach(turningSpeed, turningSpeedMax * turningDirection, turningSpeedIncrement);
direction += turningSpeedIncrement;

如果你想以“平滑”的方式将你的精灵旋转 45 度,你唯一能做的就是绘制,比方说,再旋转 3 mid-frames。不管怎样,精灵越多,动画就会越流畅。光靠两个精灵是做不出平滑转弯的。

不要依赖GM的转弯功能,还是自己画相框吧,相信我