Modify Velocity Resulting from Collision Directly?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Astrimedes
Posts: 4
Joined: Wed Jan 04, 2012 3:51 am

Modify Velocity Resulting from Collision Directly?

Post by Astrimedes »

As always, thank you, Norbo, on behalf of all the hobbyist developers out there using your awesome engine!

I'm trying to create a pseudo-2D vehicle combat game using BEPU for the physics, and then drawing simple 2D sprites from a top-down perspective.

I'm having trouble controlling the behavior of objects to achieve this "pseudo-2D" effect. Basically, objects shouldn't interact in a way where one vertically overlaps another in any way. Under normal circumstances, this won't really happen - I've set the shapes of all the vehicles to just be simple boxes, both to ease the computational burden of collision detection (I assume), and to prevent sloped objects from riding up on each other. However, during high-speed collisions in particular, objects will often end partially on top of each other.

I've looked a little at the CharacterControllers, particularly the vertical motion constraint, but unless I'm doing something wrong, it seems that you can still jar an object out of position with the VerticalMotionConstraint, in the case of a high-speed collision. Position and orientation corrections can be pretty sloppy for my purposes - the user isn't seeing anything at all along the Y axis because of the top-down view and the fact that the only visual representation is a sprite drawn at a particular X, Z location. If something needed to be teleported back down to the ground, for example, it wouldn't be problematic because the user wouldn't notice it, as long as it happened really quickly and didn't muck up collision response.

Ideally, at the time of a verified collision I would like to remove the vertical element from the forces resulting from the collision, perhaps redirecting it in order to preserve the total force involved. I have explored the Pair and Contact objects, and can't seem to find an obvious way to get at this resulting response force. Is this even possible? I realize this approach may be wrong-headed or impossible, but it seemed the most elegant way to address this situation, since the only time I really need to manage vertical behavior is during/immediately after collisions.

For reference, these collisions are occurring at up to 100 units of speed, involving box-shaped objects sized about 1-2 units per side.

So, is it possible to modify an entity's collision response force directly in any way? Is there something else I'm missing here?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Modify Velocity Resulting from Collision Directly?

Post by Norbo »

Ideally, at the time of a verified collision I would like to remove the vertical element from the forces resulting from the collision, perhaps redirecting it in order to preserve the total force involved. I have explored the Pair and Contact objects, and can't seem to find an obvious way to get at this resulting response force. Is this even possible? I realize this approach may be wrong-headed or impossible, but it seemed the most elegant way to address this situation, since the only time I really need to manage vertical behavior is during/immediately after collisions.

For reference, these collisions are occurring at up to 100 units of speed, involving box-shaped objects sized about 1-2 units per side.

So, is it possible to modify an entity's collision response force directly in any way? Is there something else I'm missing here?
Modifying the collision response calculation would be quite a bit of work; it would amount to rewriting the collision response constraints to be 2d.

At that speed, I would first recommend enabling continuous collision detection by setting the involved entities' PositionUpdateMode to Continuous if it isn't already. That will help limit the amount of penetration that can occur, lowering the chance that the collision solver will think the quickest way to separate the objects is up or down as opposed to horizontal.

If the objects are supposed to never move along the Y axis, then setting the Y component of the entities' linear velocities to 0 every frame and adding in some kind of position correction would do the trick (set position Y to desired height, or introduce extra velocity to correct the position error). Another option is to use a LinearAxisMotor with one connection set to null.

This works best if the entities can only rotate around the Y axis as well. Setting the first and third rows of the LocalInertiaTensorInverse to zeroes can do this.
Post Reply