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 » Wed May 08, 2019 1:25 am

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.

Code: Select all

if not obey then
  holdAtGunpoint = true
end

User avatar
pgimeno
Party member
Posts: 1943
Joined: Sun Oct 18, 2015 2:58 pm
Location: Valencia, ES

Re: How to do a one-off collision?

Post by pgimeno » 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.

User avatar
Darlex
Party member
Posts: 118
Joined: Sun Sep 24, 2017 10:02 am
Location: absolutely not Chile
Contact:

Re: How to do a one-off collision?

Post by Darlex » Wed May 08, 2019 4:26 pm

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
culdud uwu

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 » Thu May 09, 2019 12:46 am

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

Code: Select all

if not obey then
  holdAtGunpoint = true
end

Post Reply

Who is online

Users browsing this forum: dwilso and 12 guests