Box2D Note

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Box2D Note

Post by rude »

I just discovered this, in the Box2D Python manual:
Box2D works with floating point numbers, so some tolerances have to be used to make Box2D perform well. These tolerance have been tuned to work well with meters-kilogram-second (MKS) units. In particular, Box2D has been tuned to work well with moving objects between 0.1 and 10 meters. So this means objects between soup cans and buses in size should work well.

Being a 2D physics engine it is tempting to use pixels as your units. Unfortunately this will lead to a poor simulation and possibly weird behavior. An object of length 200 pixels would be seen by Box2D as the size of a 45 story building. Imagine trying to simulate the movement of a high-rise building with an engine that is tuned to simulate ragdolls and barrels. It isn't pretty.

*** Caution ***

Box2D is tuned for MKS units. Keep the size of moving objects roughly between 0.1 and 10 meters. You'll need to use some scaling system when you render your environment and actors. The Box2D examples do this by using an OpenGL viewport transform.
Damn it. Love.physics was created with pixel-units in mind.
SnakeFace
Prole
Posts: 28
Joined: Tue Aug 19, 2008 2:45 pm

Re: Box2D Note

Post by SnakeFace »

Ouch. How can games have MKS? I find this intriguing without some sort of coded length system, which would be pointless, no?
Lovely quotes
somewhere within the jungle of administrative doom - rude
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Box2D Note

Post by rude »

MKS makes sense in a 3D game, but we want pixels in 2D.

So ... any suggestions as to how we should deal with this? Add viewport transformations? A potential problem would then be to maintain pixel-perfection (visually) ...
SnakeFace
Prole
Posts: 28
Joined: Tue Aug 19, 2008 2:45 pm

Re: Box2D Note

Post by SnakeFace »

I don't see the problem?
Lovely quotes
somewhere within the jungle of administrative doom - rude
User avatar
nightvenom
Prole
Posts: 36
Joined: Sat Aug 16, 2008 3:07 pm

Re: Box2D Note

Post by nightvenom »

Does this pose a problem to a side scroller ?
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Box2D Note

Post by rude »

The problem is that, according to Erin Catto, Box2D does not really handle well with moving object bigger than 10 units (although I've never noticed any problems). I normally use pixel-units, which means that I rarely use anything under 30-50 pixels(/units).

It may not matter that much though. The simulation may be a little inaccurate and not "correct", but that's probably not significant for most games.
nightvenom wrote:Does this pose a problem to a side scroller ?
Probably not.

I guess we'll have to provide a way to set the viewport in the next version, though.
User avatar
Lord Tim
Prole
Posts: 30
Joined: Sun Jul 20, 2008 4:07 am

Re: Box2D Note

Post by Lord Tim »

Does this only affect stuff when you use "setMassFromShapes( )"? Couldn't you manually set the mass of objects to work correctly?
User avatar
muku
Prole
Posts: 18
Joined: Wed Aug 20, 2008 11:35 am

Re: Box2D Note

Post by muku »

I haven't used Love.physics yet, so excuse if this doesn't make sense, but would it be possible for the physics interface to simply scale all pixel units it is passed by a certain amount? That scaling factor could also be set by the user, if he needs to.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Box2D Note

Post by rude »

Of course that's possible, but it would involve one multiplication for each ingoing and outgoing numeric value.

But, if we want to keep our precious pixel units, I suppose that would be the way to go.
User avatar
muku
Prole
Posts: 18
Joined: Wed Aug 20, 2008 11:35 am

Re: Box2D Note

Post by muku »

Floating point multiplications are dirt cheap on modern CPUs though; even a Lua function call has more overhead probably. So performance would hardly be an issue. One would just have to go through all relevant API functions and apply this scaling everywhere, which would be a slight annoyance, I assume.
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests