如何使用内置于物理学中的游戏制作人来创建射击子弹



我是GameMaker的新手,也是制作游戏的新手,在我的第二个游戏中,我只打算使用物理构建的GameMakers。这是一个RPG游戏,我很难让那个家伙开枪。我可以把子弹放在房间里,按需要的角度放。你通常可以在这里使用对象名称。速度=你想要的速度。但是!使用物理学,你可以使用phy.speed,但这是一个只读变量。所以我半使用phy_speed_x和phy_speed_y。但我该如何让它朝着子弹物体的方向射击呢?这是我目前掌握的代码。

// Player shoot
var shootButton = mouse_check_button_pressed(mb_left);
var bulletSpeed = 10;
if (shootButton) {
    bullet = instance_create(ot_player.x, ot_player.y, ot_bullet);
    bullet.phy_rotation = phy_rotation;
    bullet.phy_speed_x = bulletSpeed;
    bullet.phy_speed_y = bulletSpeed;
}

我试着把许多不同的变量放在我有bulletSpeed变量的地方,但似乎什么都不起作用。我被困在这里了,我看了很多教程,读了很多东西,但什么都没用!

我想明白了。

var shotButton=mouse_check_button_pressed(mb_left);var bulletSpeed=10;

if (shootButton) {
    bullet = instance_create(ot_player.x, ot_player.y, ot_bullet);
    with(bullet) {
        phy_rotation = other.phy_rotation;
        ldx = lengthdir_x(15, -phy_rotation)
        ldy = lengthdir_y(15, -phy_rotation)
        physics_apply_impulse(x, y, ldx, ldy);
    }
}

最新更新