Physics Engine - Turn It Off?

So why do I want to do this?

The currently game I am working on really needs a simple collision/physics implementation not Box2D or other system.

In fact the only objects that move follow a strict path and do not really take into consideration the physics world.

So how?

My specific question would be … how can I stop Box2D from even existing in my game?

If this is not possible, what kind of overhead am I looking at for it running through zero physics bodies every update?


Codea doesn’t use physics by default, so you don’t need to turn it off.

You don’t need physics to do simple collisions, just test how close the bodies are to each other.

Even if you want them to bounce off each other, or fall or jump, you can do it without gravity.

What type of collisions do you want?

So how do you “turn on” the physics if it does not use it by default? Does it “activate” when a physics body is created? What if I then destroy that body?

And yes I know I can do collisions without a physics engine. I have written my own before (different language) that I still use for a lot of projects.

Turning on the physics engine is no different than turning on the screen display. If you write code to display something on the screen, it will. If you write code to use the physics engine, it will. There is no on or off, it’s always there ready to use or not use. - why don’t you read some references and tutorials? We are happy to help solve problems, but we don’t have time to provide personal tuition.

I’ve written about physics here, start from the bottom, or look at my Codea ebook, linked from the index page of my blog.

@Ignatz - I was not asking for a tutorial but rather, what I thought, a simple answer to a straight forward question.

@dave1707 - That was the point of my question. I guessed that it was “always on ready to use” however that would mean that the physics engine itself is always scanning for physics bodies.

Ah well! It was really just a question out of curiosity while writing a TMX map reader/implementer.

Thank you for the replies. I will just pretend it does not exist and go forward with what I am doing.

Thanks again,

So how do you “turn on” the physics if it does not use it by default? Does it “activate” when a physics body is created? What if I then destroy that body?

This wasn’t a straightforward question.

This is a question on how to use physics.

And that’s what I helped you with. It’s not that the physics engine is running and waiting for you to use it. It’s not doing anything until you actually write code to use it. That would be like saying a car sitting in the garage is waiting for you to get in and drive it. It’s there, but it’s not doing anything until you start it and drive it.

@dave1707 - I understand your analogy, however what I was getting at is that in Codea we do not create the Box2D world in which the physics bodies exist.

Normally (in other languages) you would create the world and that world would then be “operational” with or without bodies.

It would always be updating, even if there was nothing to update.

Unless I have misunderstood Box2D completely.

D In Codea, you don’t create a physics world, you create physics objects. Once a physics object is created, that object then runs under the control of the physics engine. That means you can have physics objects and normal objects next to each other on the screen and they won’t interact with each other. Only objects created as physics objects will react under the control of the physics engine.

EDIT: A physics object, even after it no longer shows on the screen, is still under the control of the physics engine. If you create a physics object and let it fall under the control of the engine, even after it leaves the screen it will still be falling at the speed of gravity until you stop the program.

@dave1707 - I think there has been a misunderstanding.

I know all of what you have said about Box2D and Codea itself.

I even understand that the physics objects still operate until disposed or garbage collected.

My original question was regarding the Physics World itself.

And in essence you have answered the question - the world is always there calculating away. - I believe you are incorrect. The physics engine has nothing to calculate unless physics objects exist, so it is inactive if there are none. It only operates on physics objects, and nothing else.

The bottom line is that there is no overhead from Box2D if you have no physics objects.

@Ignatz - The physics engine can not be inactive if it waits for bodies to exist. It must be at the very least scanning for bodies every update.

Yes this is a low overhead and should not make much difference to what I am doing.

I don’t know which scenario happens exactly. If some small amount of physics engine code scans for physics bodies and processes them, or the physics bodies calls the physics engine code. So in the first scenario, a small part of the physics engine is always running, in the second none of it is running until an object is created.

@dave1707 - Interesting idea (the second one). The “obvious” version, at least to me, is the first.

However it would be interesting to know.

Thank you again.

I would expect that the compiler looks for physics references when starting the program, and only loads the Box2D library if required, but it’s academic because the overhead would be minuscule.

@Ignatz - now that is something I completely forgot about - the compilation phase.

Man do I feel stupid now :blush:

That’s ok, I feel stupid at least once a week! :wink: