Checking if object is no longer colliding with collision event

D

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?
 
D

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.
 

RangerX

Member
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)
then
{
set stats to X
}
else
{
set stats to Y
}
 
R

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.
 
D

Daz@mbi

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.
That works perfectly, thank you :)
 
A

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:

Code:
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.
 

gnysek

Member
You can use an alarm event as well. Set the alarm to a small number of steps this way in the Step event:
Code:
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.
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.
 
Top