GML [SOLVED] Singular Collision Testing?

D

DIYDamian

Guest
I'm making a physics based platformer that has a mechanic where when you touch a certain object, your gravity switches. I'm wondering how you can make it where it only activates once when the player touches the object, but then the player must re-enter the object before activating it again. The way I tried caused the gravity to switch every step the player was colliding with the object.
 

samspade

Member
I'm making a physics based platformer that has a mechanic where when you touch a certain object, your gravity switches. I'm wondering how you can make it where it only activates once when the player touches the object, but then the player must re-enter the object before activating it again. The way I tried caused the gravity to switch every step the player was colliding with the object.
Never used the physics engine before, so this might not work, but I would try the following code in the switch object:

Code:
///create event

triggered = false;

///step event
if (collision_with_player == true) && (triggered == false) {
     triggered = true;
     //code to switch gravity
}

if (instance_exists(obj_player)) {
     if (distance_to_object(obj_player) > reset_distance) {
          triggered = false;
     }
}
This will make it so that the object will be triggered when it first comes into contact with the player, but cannot be triggered again until the player has moved a certain distance away from it. You could set the re-triggering code to be anything you wanted, distance, hit another switch somewhere else, etc.
 
D

DIYDamian

Guest
That seems to have worked just fine. Thanks for the help!
 
Top