Search code examples
game-maker

GameMaker: How to freeze enemies temporarily?


I tried to set the Enemy.path_speed=0 and then set an alarm[0]=5, when it gets to alarm[0] it simply set Enemy.path_speed=100(the default value) again. But it does not work. enemies are frozen forever. How else can I freeze the enemies temporarily when I hit the space?


Solution

  • path_speed = 0 and path_speed = 100 is not good idea. As example, objects can have different speed. I use speed factor, like speed = normal_speed * k where k is 1 for normal speed and 0 for full stop.

    Enemy Create event:

    spd = irandom_range(5, 10) // different speed, just as example
    path_start(path0, spd, 1, true)
    path_position = random(1)
    k = 1
    

    Enemy Step event:

    path_speed = spd * k
    

    Controller Space key pressed event:

    with (o_enemy)
         k = 0
    
    alarm[0] = 3 * room_speed
    

    Controller Alarm0 event:

    with (o_enemy)
         k = 1
    

    And finished gm-project