Moving the world bounding box

I've got a side scrolling platformer. Currently the world bounding box is set up to be twice as large as the screen area. I'm only updating objects within that area, so I don't have to worry about anything outside of it falling through or not doing collision detection since it isn't moving anyways. Since I scroll the world, things will eventually have coordinates that are outside the starting bounding box range. Is it problematic if I move the world bounding box, just like I move my game's world coordinates? Or does the world box have to be stationary at all times?
Repositioning the world AABB is not supported.

I would just make the world box big enough to contain your entire world.

Another approach would be to recenter all your physics objects on the new "room". This would allow you to use a smaller world box. I designed Box2D to support this, but I haven't tried it yet. There may be bugs.
Hmm I wonder if that will be problematic to contain my entire region. I was envisioning having very large levels, and I'm not sure then if there'd be too many objects to let the engine run efficiently. Would a viable approach be to disable collision detection for objects not on screen (I guess set them to sleeping)?
When you say recenter objects on a new "room," do you mean something like having a whole grid of b2Worlds and passing objects from one to the other as they reach the boundaries? Or am I misunderstanding?

I imagine getting things to work correctly at boundaries could be tricky, as you'll really need to keep the object in both worlds whenever you've got some overlap, but as long as the bodies pointed at are the same, this might not actually be too problematic.

Perhaps in a future update some helper methods for this sort of thing would be useful, seeing as this issue has come up a few times already - maybe instead of freezing objects at the world boundary, an optional set of adjoining worlds could be specified, and the objects could be properly passed between them (when the object AABB extends beyond the world but still overlaps it) and removed as necessary (when the object AABB no longer overlaps the world) by the engine. If everything worked out properly this would also allow for your standard arcade torus-world (each side of the world passes the object to the same world on the other side), which I think is a little tricky to do by hand with the current setup.

There might be some issues, though, with islands that span multiple worlds, I'm not sure how that would work out in practice...
The broad-phase can handle worlds that are 5km x 5km without much trouble. This gives an 8cm resolution in the broad-phase AABBs, which is small enough if you don't have lots of tiny shapes.

I would go to a 32bit broad-phase long before I would consider using multiple worlds. Actually, I've never heard of people using multiple, interacting worlds successfully.

I'll try to clarify what I mean by recentering. Let's say your world in 10km wide, but you setup b2World to be 1km wide. Now let's say your game defines rooms to be 100m wide. Then your world has 100 rooms horizontally. Most of these rooms extend beyond the b2World box, but they shouldn't have any actors loaded anyhow (unless it's multiplayer, but I'm talking about single player here).

A nice way to keep the object count down is to only have actors loaded for the room your player is in, and perhaps the adjoining rooms. Then as the player moves from room to room, far away actors are dumped and closer actors are loaded. All this time, the player is moving through the world getting farther from the origin.

Moving far from the origin may cause numerical problems, not just in physics because when you try to find the distance between two points far away from the origin, you get less bits of precision than you would close to the origin. To solve this, you can shift the world origin (and all the actors) to the local origin of the current room. The added benefit is that you can use a smaller b2World bounding box.

I'm not necessarily suggesting you use recentering, it is just one of many possibilities.
So what other methods would you suggest then?
It depends. If the game engine has some concept of relocating the origin, then I would want to mirror that in the physics engine. Otherwise I would just use a large world AABB and use a 32-bit broad-phase if necessary.

It is much simpler to have the game and physics engine use the same coordinate system.
I was just about to ask about this...glad I found it.

If you're still around Dirk, what approach did you end up taking?

This re-centering sounds a bit cumbersome. I was going to make all the objects outside the "room" or current screen just sleep... but that might still create too many objects.

I could unload them, but then I'd either have to save them to a temp file, or have them reset every time you revisit an area. I haven't decided if resetting is a big problem yet.

Regardless, 5km x 5km, at ~25m per screen, gives us about 200x200 screens to work with. I'm not sure if that's enough. I wanted to have pretty big worlds too. Perhaps I'll just load a new map when the character reaches the end...

Original thread: https://box2d.org/forum/viewtopic.php?t=75