Search code examples
variablesgame-makergml

Game maker studio place_meeting


//obj 1 has that:
if (place_meeting(x,y, obj_nomatter)){
 global.points -= 1;
 moveawayfromobj_nomatter();
 // obj 1 rotates.
}

The problem is that the points drops sometimes one or seven. Any ideas for algorithms? Thank you!


Solution

  • you are using that in the step event so it calls the action one or seven times if you still collide for seven steps

    one method is to use a timer or a variable

    so: this is the method using the variable

    var ones = false;
    if(!ones) {
      if(place_meeting(x,y,obj_nomatter)) {
        global.points -= 1; 
        ones = true;
      }
    }
    

    this is the method using the timer

    step event:
    if(place_meeting(x,y,obj_nomatter)) {alarm[0] = room_speed;} 
    //to use the room_speed, 30 for default (a second)
    
    alarm[0]:
    global.points -= 1;
    
    //with this method if you collide more than room_speed global.points keeps going down