Page 1 of 1
How to do a one-off collision?
Posted: Wed May 08, 2019 1:25 am
by guy
I'm making a really small game where the player has to reach a door to get to the next level. The door has really simple collision detection where if the player is colliding with it then the collision function returns true. I just wanted to know if there's a way to make it return true just one time instead of every frame when something is colliding with it.
Re: How to do a one-off collision?
Posted: Wed May 08, 2019 11:05 am
by pgimeno
Have a variable 'door_collided' which is set to false at the beginning of the level. Check for collision only when it is false. Set it to true when the player collides with the door.
Re: How to do a one-off collision?
Posted: Wed May 08, 2019 4:26 pm
by Darlex
pgimeno wrote: ↑Wed May 08, 2019 11:05 am
Have a variable 'door_collided' which is set to false at the beginning of the level. Check for collision only when it is false. Set it to true when the player collides with the door.
Or a table named Collided with all the objects that are currently in collision. like
Code: Select all
if collided["door"] then
next_level()
elseif collided["monster_guy001"] then
lives = lives -1
restart_from_checkpoint()
--ETCETERA
Re: How to do a one-off collision?
Posted: Thu May 09, 2019 12:46 am
by guy
Thanks a bunch. I didn't realize it was so simple!