destroy physics object on collision ?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
PGUp
Party member
Posts: 105
Joined: Fri Apr 21, 2017 9:17 am

destroy physics object on collision ?

Post 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 ?
-
User avatar
xNick1
Party member
Posts: 267
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

Re: destroy physics object on collision ?

Post 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
PGUp
Party member
Posts: 105
Joined: Fri Apr 21, 2017 9:17 am

Re: destroy physics object on collision ?

Post 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
-
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 88 guests