How to verify collision with?

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
Cauan
Prole
Posts: 22
Joined: Thu Mar 09, 2023 5:58 pm

How to verify collision with?

Post by Cauan »

Hello, i am having a problem that the collision not is verified, (AABB) collision type
This is the code( only the collision lines )

Code: Select all

for i = 1, #obj do
    if checkCollision(player.x,player.y,player.size,player.size, obj[i].x,obj[i].y,obj[i].size,obj[i].size) then
        if obj[i].numeroaleatorio == 8 or obj[i].numeroaleatorio == 5 or obj[i].numeroaleatorio == 15 or obj[i].numeroaleatorio == 18 or obj[i].numeroaleatorio == 9 or obj[i].numeroaleatorio == 1 or obj[i].numeroaleatorio == 20 then
       table.remove(collidedwith, i)
       pontos = pontos + 1
       if pontos >= 6 then win = true gameover = false end
       else 
           if not pontos <= 0 then pontos = pontos - 1 else gameover = true win = false end
           end
    end
    end
I'm me, and you are you
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to verify collision with?

Post by darkfrei »

First was not easy to understand that obj is a list of objects, not an object.

By removing make the backward iteration:

Code: Select all

for i = #objects, 1, -1 do
	local obj = objects[i]
	if something () then
		table.remove(objects, i)
	end
end

Code: Select all

local trueNumbers = {8=true, 5=true, 15=true, 18=true, 9=true, 1=true, 20=true}
for i = #objects, 1, -1 do
	local obj = objects[i]
	if checkObjCollision (player, obj) and trueNumbers[obj.number] then
		table.remove(objects, i)
		bridgesAmount = bridgesAmount + 1
		win = isWin ()
		gameover = IsGameOver ()
	end
end

Last edited by darkfrei on Sat Mar 25, 2023 10:05 pm, edited 1 time in total.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How to verify collision with?

Post by slime »

Hi, please use the Support and Development subforum for these threads. This Ports subforum is just meant to be about different platforms people have got love to run on.

(edit: I moved all your threads for you. Please stop posting general support questions in the Ports subforum.)
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 46 guests