Moving objects with code, but with physics

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Moving objects with code, but with physics

Post by Danthekilla »

Hey norbo, we are adding some more features to our editor for the game we are making so that we can setup paths for objects to follow.

So we can create a platform and tell it to follow a path with certain rotations and positions on the way (kinda keyframed) with a few modes of smoothing etc...

We were wondering before we start on how to make it actually move the objects but with the correct physics being applyed, so we can move objects without them just penertrating other objects and so the pathed objects will create the correct collsions and forces in the simulation but still move with no acceleration and not react to physics themselves.

Any idea how we can do this as it is integeral to the next 4 games we have planned. (this editor and engine that we are developing will power them all)

Thanks for any help you can provide.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Moving objects with code, but with physics

Post by Norbo »

For kinematic entities, one way to go about doing it is to have a method that computes the next frame's position and orientation using whatever path, curve, or target is available. The velocity needed to reach that next position over a single timestep can then be computed. For linear position this is relatively easy, the velocity is just the offset vector divided by dt. For orientation, this can be a little trickier, but you can do something like get the intermediate quaternion from the starting orientation to the second and convert that to an axis-angle representation. Angular velocity can be thought of as axis*angle, where the angle is the radians per second that the entity is rotating around the axis.

Since kinematic entities aren't going to be affected by any other collision, forcing the velocity to a certain value each frame should get the entity where it needs to go. Dynamic entities are a little trickier in that they can be shoved around. Simply setting the velocities can work to some extent for them as well, but will be less stable in collisions. This is why the SingleEntityLinearMotor and SingleEntityAngularMotor were added recently. They use the velocity solver to push the entities around which will interact with collisions in a much more stable way.

I also plan to include a keyframing/pathfollowing-style system in v0.13.0 that would handle all of this automatically (though again, it could take a while to be released).
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Re: Moving objects with code, but with physics

Post by Danthekilla »

Cool well i will take all that on board and give it a try.
Ill let you know how it all goes.

Thanks.
Post Reply