Page 1 of 1

destroy physics object on collision ?

Posted: Sat Jun 17, 2017 10:48 am
by PGUp
For example, I have a physics rectangle and 10 physics circle, every time the rectangle touches the circle, the circle will be destroyed, to check contact I use world:setCallbacks on load function and use beginContact function to check the collision, tried it.. and every time the rectangle collide with the circle, 1 or more circle will disappear.. anyone know how to fix this ?

Re: destroy physics object on collision ?

Posted: Mon Jun 19, 2017 1:21 pm
by xNick1
If I understand your problem, then you should check which circle you hit in your update function and then remove it. ex:

Code: Select all

    for i,c in ipairs(circles) do
        if c.x is colliding with my player then
            table.remove(circles, i)
        end
    end

Re: destroy physics object on collision ?

Posted: Sat Jun 24, 2017 4:24 am
by PGUp
xNick1 wrote: Mon Jun 19, 2017 1:21 pm If I understand your problem, then you should check which circle you hit in your update function and then remove it. ex:

Code: Select all

    for i,c in ipairs(circles) do
        if c.x is colliding with my player then
            table.remove(circles, i)
        end
    end
you mean.. check all of them manually ? like c.x = player.x and c.y = player.y ? i dont really like to use that