How to do a one-off collision?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
guy
Prole
Posts: 11
Joined: Wed Sep 19, 2018 7:10 pm

How to do a one-off collision?

Post 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.
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: How to do a one-off collision?

Post 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.
Darlex
Party member
Posts: 128
Joined: Sun Sep 24, 2017 10:02 am
Location: Chile
Contact:

Re: How to do a one-off collision?

Post 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
Hi! I wish you have an amazing day!
User avatar
guy
Prole
Posts: 11
Joined: Wed Sep 19, 2018 7:10 pm

Re: How to do a one-off collision?

Post by guy »

Thanks a bunch. I didn't realize it was so simple!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot] and 3 guests