1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Checking if object is no longer colliding with collision event

Discussion in 'Programming' started by Daz@mbi, Jun 21, 2016.

  1. Daz@mbi

    Daz@mbi Guest

    Is there an efficient or simple way to check if an object is no longer colliding with another object when using the collision event?
  2. graviax

    graviax Guest

    Why do you want to do that?
  3. Daz@mbi

    Daz@mbi Guest

    I'm using the collision event to change variables that belong to the player, then changing them back when the player is no longer colliding.
  4. RangerX

    RangerX Member

    Jun 20, 2016
    You need to think your stuff the other way around. Check if the object is colliding.

    Use the "place_meeting()" function (look up the manual for arguments) in this way:

    Step event in the hero:

    if (place_meeting with the other object)
    set stats to X
    set stats to Y
  5. graviax

    graviax Guest

  6. rui.rosario

    rui.rosario Guest

    If you still want to perform that check with the Collision Event then maybe you can do something like this (this is untested, but I believe the events happen in the expected order).

    1. On the Begin Step event set a variable (e.g. collision) to false;
    2. On the Collision Event set the variable to true;
    3. On the End Step event see if the variable is true, if it is then a collision occurred and you can perform the remaining logic.
  7. Daz@mbi

    Daz@mbi Guest

    That works perfectly, thank you :)
  8. Aura

    Aura Guest

    You can use an alarm event as well. Set the alarm to a small number of steps this way in the Step event:

    if (place_meeting(x, y, obj_spike)) {
       alarm[0] = 2;
    The alarm would keep on resetting to 2 as long as there is a collision. As soon as the collision ends, the alarm would start to count down and trigger the Alarm 0 event, producing a Collision End alternative, that is, Alarm 0.
  9. gnysek

    gnysek Member

    Jun 20, 2016
    It's important to not setting alarm to 1 in this case, as alarms generally triggers when it's equal to 0, so it may be set to 0 right before NEXT collision event in next frame, and will be executed every time before/after collision.

    Generally in your case, setting variable in "begin step" to false, and in collision to true, should be enough.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice