我正在制作一个自上而下的射击游戏,玩家的枪偏离了物体的坐标。我正在使用 GameMaker:Studio,所以 x 和 y 坐标是对象的中心。图像的偏移设置在这里:
bullet_offset_x = 30;
bullet_offset_y = 28;
这是开枪的代码:
var xpos = x + (bullet_offset_x * cos(degtorad(direction))) - (bullet_offset_y * sin(degtorad(direction)));
var ypos = y + (bullet_offset_x * sin(degtorad(direction))) + (bullet_offset_y * cos(degtorad(direction)));
var flash = instance_create(xpos, ypos, obj_flash);
with (flash){
direction = other.direction;
image_angle = other.direction;
}
我使用以下公式来放置枪口闪光灯:
x' = x cos(角度) - y sin(角度)
y' = x sin(角度) + y cos(角度)
所以:
xpos = x + x' 和 ypos = x + y'
但是,当我运行代码时,当角度为 0/360 时,枪口闪光灯正确定位,否则关闭。我计算错了吗?
图片:
正确的
不正确