love.physics is the most frustrating thing ever.

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: love.physics is the most frustrating thing ever.

Post by vrld »

Tesselode wrote:3. Use an if statement: if (shape1 = your first shape and shape2 = your second shape) OR if (shape1 = your second shape and shape2 = your first shape)
4. Figure out which bodies the shapes apply to so you can make them react properly.
At least those two points can be handled more gracefully:

You can attach data to a shape using Shape:setData. This data can be any Lua value; especially it can be a table. Attach a table with the body and some id field:

Code: Select all

theShape:setData {
    body = theBody,
    id = theID, -- this again can be any lua value
}
Now create a dispatcher table, which will hold functions for every pair of shapes that you want to handle collisions:

Code: Select all

dispatcher = {}
dispatcher[id1] = {}
dispatcher[id1][id2] = function(a, b) --[[ do stuff --]] end
dispatcher[id1][id3] = function(a, b) --[[ do stuff --]] end

dispatcher[id2] = {}
dispatcher[id2][id4] = function(a, b, contact) --[[ do stuff --]] end
The collision callback(s) will use the dispatcher table(s) to handle collisions:

Code: Select all

function persist(a,b,contact)
    if dispatcher[a.id] and dispatcher[a.id][b.id] then
        dispatcher[a.id][b.id](a,b,contact)
    elseif dispatcher[b.id] and dispatcher[b.id][a.id] then
        dispatcher[b.id][a.id](b,a,contact)
    end
end
You can modify this approach to support things like collisions with groups (e.g. lava-pits, trampolines, ...) by using a group id which will be used for dispatching.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Re: love.physics is the most frustrating thing ever.

Post by Tesselode »

ivan wrote: I assume your platforms are not moving so you can just create static shapes (whose density/mass is 0).
I did mention rotating platforms.

I see what you guys mean about the shapes being separate from the bodies, but it would be nice if the shapes could be automatically calculated from a polygon or something. I wish all this physics stuff required less code.

Also, I've figured out how Box2D works; I used it to make Tilt, but then a bunch of people experienced strange glitches and I didn't know why. And it's hard to tell what's causing the glitches because of how much code I had to use. So I started recoding it, but it's a lot of code and it's quite tedious. Part of that, though, is having lots of different screens and transitions. Maybe I'll try using gamestates.

Edit: This topic is a little pointless; it was really just me venting about how much code it takes to write anything in Box2D. I think I will go back to working on Tilt, maybe make a couple of alpha releases to test basic functionality, and then start the coding with good organization in mind. I imagine that's how most people make their games anyway.
User avatar
slime
Solid Snayke
Posts: 3154
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.physics is the most frustrating thing ever.

Post by slime »

This little utility might be useful to people, although it's not free and it doesn't have a specific LÖVE exporter (yet?)
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: love.physics is the most frustrating thing ever.

Post by Xgoff »

i found it annoying that there is apparently no way of using just the collision detection without having to drag the physics into it one way or another... which would generally mean that certain things you would try to do would have side effects like making objects ignore collision detection completely

oh and b2Assert
User avatar
slime
Solid Snayke
Posts: 3154
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.physics is the most frustrating thing ever.

Post by slime »

If you're talking about collision detection vs collision response, you can have any shape be a Sensor (Shape:setSensor).
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests