Box2D, performance, and error(!) questions

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Box2D, performance, and error(!) questions

Post by Taehl »

A few random Box2D questions that will assist my current project:

1) What's the fastest type of shape? Circles, right?
2) How can I boost the performance of Box2D? I tried using setFixedRotation on my circles, but that only seemed to give ~1 FPS more.
3) Is there any way to do a world:update() which moves everything, but skips collision? I figure, doing collision every other frame or something would be good enough, and would reduce CPU usage.
4) In a world with many bodies, what would be the best-performing kind of weapon? Circles with setSensor, raycast "hitscan", something else? If fixtures with setSensor are fast, would someone mind explaining how to use them, please? Their wiki page is very sparse. Do I use them will collision callbacks like regular fixtures?
5) Will using fixture:setMask improve performance?
6) Is there any way to apply a small amount of friction (ie, air friction) to an entire world?
7) Why is it if I make bodies with minuscule, or even 0 mass, they can still shove other bodies around? How can I make them less "pushy"?

Oh, and this one is important: 8) How can I determine the force with which two bodies have collided? I want to do damage based on how hard they hit things.

Thanks in advance. The new Box2D in 0.8.0 pretty much made the little I used to know obsolete.

EDIT) I'm getting a strange error: "Box2D error: IsLocked() == false". Outright crashes Love2D. Am I not allowed to add bodies within the scope of a collision callback?
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
timmeh42
Citizen
Posts: 90
Joined: Wed Mar 07, 2012 7:32 pm
Location: Cape Town, South Africa

Re: Box2D, performance, and error(!) questions

Post by timmeh42 »

I only know the answer to (6) - it's called Damping, somewhere under here: http://www.box2d.org/manual.html#_Toc258082973
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Box2D, performance, and error(!) questions

Post by Taehl »

Thanks, I'll look into that.

I tried moving my body-creating stuff outside of the collision callback (basically, dump it in a list and don't do it until after world:update), and the crashing seems to have stopped. But it would be good to know what is and isn't allowed in collision callbacks.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
spectralcanine
Citizen
Posts: 65
Joined: Sat Dec 22, 2012 8:17 am

Re: Box2D, performance, and error(!) questions

Post by spectralcanine »

You are not allowed to change the state of Box2D inside its collision callbacks (if you think about it, this is very reasonable, as this can cause all sorts of nasty side effects), which in English means you can't create or destroy objects. Keeping whatever needs to be change in a list to later be processed is indeed the common way to do it.

Sensors detect collisions but don't respond to them, you can process them in the usual callbacks.

Masks allow you to filter collisions. E.g. if you don't want bullets to hit each other because it will make the game slow, you can use masks. They are useful for both game logic and stepping efficiency.

In C++ Box2D the PostSolve callback is given the impulse of the collision (aka the strength of it), check what Love2D gives you.

In general, if you have Box2D questions, it makes sense to first check the actual Box2D manual. Even though it's for C++, you can get a good idea of what's what.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], darkfrei and 64 guests