Page 1 of 1

How to verify collision with?

Posted: Sat Mar 25, 2023 4:12 pm
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

Re: How to verify collision with?

Posted: Sat Mar 25, 2023 9:46 pm
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


Re: How to verify collision with?

Posted: Sat Mar 25, 2023 9:48 pm
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.)