1

我一直试图让一个 NPC,在我的情况下是一个僵尸,在我的游戏中跟随我当然无济于事。我正在使用以下脚本让我的角色移动

if(keyboard_check(vk_left)){
    sprite_index = spr_player;
    x -= 4;
}

if(keyboard_check(vk_right)){
    sprite_index = spr_player;
    x+= 4;
}

if(keyboard_check(vk_down)){
    sprite_index = spr_player;
    y += 4;
}

NPC 对象的名称是 (obj_zombie)。

4

2 回答 2

0

正如 Jr Jimnz 所说,在这种情况下,如果您个人使用 move_towards_point(x,y,speed) 会更好,这也是我在某些情况下使用的系统!否则,您可以使用符号功能:

 if (instance_exists(//insert your player object here)) {
 x += sign(//player object.x - x);
 y += sign(//player object.y - y);}

但是标志系统不是那么方便。

对不起,我的英语不好。

于 2019-01-04T11:41:59.097 回答
0

Looking at the simple system you are using to move player object you may just make another object follow to another object (object to object) using move_towards_point(x,y,speed); function in step event of the object zombie in this way:

move_towards_point(obj_Player.x, obj_Player.y,5);

Where obj_Player is of course the name of you player object, which i dont know which is it so i just put obj_Player, you should change it to match yours.

To change the sprite to the direction its moving you can just check the direction the object is going and depending of then the sprite may change or the scale of the sprite may change.

if (direction > 90) and (direction < 270) {
   // left direction
} else {
   // right direction
}

Note: Links over some text in this answer redirect you to game maker studio reference code documentation.

于 2017-09-30T17:13:11.773 回答