0

我是 GameMaker 的新手,也是制作游戏的新手,对于我的第二个游戏,我打算使用内置于物理中的 GameMakers。这是一个角色扮演游戏,我很难让那个人开枪。我可以把子弹放在房间里,并放在它需要的角度。然后,您通常可以将 objectnamehere.speed = 用于您想要的速度。但!使用物理你可以使用 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 变量的位置放置许多不同的变量,但似乎没有任何效果。我被困在这里,我看过教程并阅读了很多东西,但没有任何效果!

4

1 回答 1

0

我想到了。

var shootButton = 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);
    }
}
于 2016-04-15T17:20:07.057 回答