PDA

View Full Version : Hands on physics control



speeder
03-27-2010, 01:21 AM
I noticed that is impossible to control the physics of the object directly without the Brain...

I use here in my projects Chipmunk physics (it is a "brother" of Box2D, the owner of the two projects seemly exchange code with each other sometimes...), and I would like to control some objects more directly...

I mean, there are the "addforce" available, but only that, a "SetVelocity" for example would be a GREAT start for this feature...

Example: I want to shoot a bullet, your code to do it (from the beer invaders) consist of using a brain to set acceleration and then request a movement, I think that this is rather clunky, why not just say to it: "SetVelocity(Vector2(0, 25))" (25 is the speed of the bullet in your example).

Likewise, it would make coding my paddle easier, as I said in other topic, SetPos breaks the physics (and I know why, it breaks on chipmunk too, it is result of desynch, altough chipmunk has a chance of breaking, Box2D always breaks), so I would have to use the physics engine own system to move the paddle, but using the brain manager is proving too cumbersome just to make a paddle follow the mouse in the X axis...

Seth
03-27-2010, 01:45 AM
Wouldn't removing all force, then using AddForce be the same as a SetVelocity command? Something to try.

I know I've done that but I don't remember which example... maybe do a global text search in the examples for AddForce.

I'd like to play with it and add more physics stuff (there are currently no support for circles or joints for instance, despite box2d supporting them) but am currently too swamped with other projects... feel free to look at the C++ source and be sure to submit a patch with any good additions.

TSO
07-14-2010, 07:39 PM
So if I wanted to take the physics test level and turn the cubes into circles I'd have to code the physics for circles to bounce like balls my self?

Guess I could look into the process but I doubt I'd figure it out...

Seth
07-14-2010, 10:49 PM
So if I wanted to take the physics test level and turn the cubes into circles I'd have to code the physics for circles to bounce like balls my self?

Guess I could look into the process but I doubt I'd figure it out...

Not exactly - Box2D already supports circle colliders, so it's more a matter of doing the following:

1. Figuring out how to instantiate a circle collider in box2d instead of the normal vector points shape
2. Figuring out a way to add and store the info for the circle in an entity, possibly by hacking up the existing collision point editor to also support adding other shapes and scaling the size up/down.
3. Planning ahead while you do this to also support joints/other later

The actual collision part should be more or less automatic.

Still, a bit of a hassle to "do it right". If you don't care about the editor being able to add/edit circle shapes than you can take a shortcut and just do it all in C++ manually.