game maker studio 2:子弹不向鼠标方向移动

game maker studio 2: bullets don't move to the mouse direction

我正在尝试在我的游戏中制作射击机制,但我无法强制子弹向鼠标方向移动。它只是在玩家对象下创建并留在他的坐标上。使用物理不会改变情况,无论 obj_bullet 只是 "uses physics"(以及传感器参数)或不使用。

它们只是停留在我创建它们的坐标上

当我在 obj_bullet 上不使用物理时,子弹精灵旋转取决于鼠标位置但仍然不移动。

我在 "create" 事件

中为我的子弹写了一个简单的代码
BulletPower=1;
bulletSpeed=10;
speed=bulletSpeed;
direction=point_direction(x,y,mouse_x, mouse_y);
direction+=random_range(-5,5);
image_angle=direction;

尝试使用 move_towards_point(mouse_x, mouse_y,bulletSpeed); 但不起作用

然后我将实例层 "Bullets" 置于所有其他之上 然后在 obj_player

的 "step" 事件中设置条件
if (mouse_check_button(mb_left)){
    instance_create_layer(x,y,"Bullet",obj_bullet);
}

而且子弹只会落在玩家坐标上。 我有理论认为子弹只是堆叠在玩家身上,但即使我不在玩家坐标上创建子弹它仍然不起作用 我也改变了玩家和子弹精灵的轴,但仍然没有结果...

我真的不明白为什么它不起作用,因为我在 youtube 教程上看到了几乎相同的代码 like this 在他们的情况下它有效。

我解决了这个问题,希望对大家有所帮助。子弹不会移动,因为变量 "speed" 将无法使用物理空间。您需要将 obj_bullet 作为物理对象(使用物理),然后在 "create" 事件

中编写代码
direction=point_direction(x,y, mouse_x , mouse_y );
phy_rotation = -direction;//it's like image angle for bullets

并制作事件 "step" 事件

phy_position_x += lengthdir_x(bulletSpeed, direction);
phy_position_y += lengthdir_y(bulletSpeed, direction);

完成!现在子弹会移动了。