Rotate the Physics World?

Hi guys,

I'm trying to simulate the physics world rotating. So say my "hero" hits a switch. I'd like to have the entire physics world rotate 90 degrees as I rotate my game layer 90 degrees. If I had, say, a ball sitting on the floor, it would immediately start falling to the right, as the world rotated, untill it hit the (previously right wall, but now the floor) floor.

Is this possible? I can't seem to find anything in the documentation referring to any world rotation properties. Any tips would be much appreciated.

Thanks!
Sunsu
That is not how you do it. You rotate your view of the world (your camer) and adjust the gravity vector (b2World::SetGravity). Done.
Thanks for your input.

Hmm. Well I did that originally. What through me off was that when I applied forces, they were still referenced the original world "rotation" and not the new one, even though I moved the gravity vector. So, it seemed that there had to be some way to tell box2d that I had changed the "view". I guess there isn't though?
sunsu wrote:
Hmm. Well I did that originally. What through me off was that when I applied forces, they were still referenced the original world "rotation" and not the new one, even though I moved the gravity vector. So, it seemed that there had to be some way to tell box2d that I had changed the "view". I guess there isn't though?

Yes, once you rotate the world, you'll need to apply the forces differently in order for the effects to appear consistent. For example, if initially a positive y impulse causes the player to jump, after a 90-degree rotation a positive x impulse will cause the player to jump.

As for your second question, no, there's no way to tell Box2D that the view has changed (IMO, that wouldn't be a very practical feature for a physics engine to have). Your best bet is probably to rotate the view and change the gravity vector (as previously suggested), and then rotate your force vectors as necessary to reflect the current orientation of the world.
Thanks so much for your help and insight! I'll attack the problem as you suggested.

-Sunsu
You could apply a gentle constant velocity on all your objects each frame if you wanted an alternative I guess, although they would never "sleep".
Hi I want to check out the alternative as you mentioned. Can you explain me the steps how can I apply the velocity??

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