Best way to eliminate penetration?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
twig314159
Posts: 7
Joined: Thu Apr 28, 2011 5:31 am

Best way to eliminate penetration?

Post by twig314159 »

In my game, I have an object controlled by the player and when the user runs into another object, I want to weld it to the player at the point they picked it up, but with a bare minimum amount of penetration.

What's the best way to minimize that penetration? It's okay if it takes a few time steps, but the quicker the better.

Since I just started playing with BEPUphysics recently I'm a bit unclear on how to create custom constraints. My game is in 2D and I'd like to constrain all my game objects to a specific plane on the Z-axis. The main reason is because I don't want to accidentally cause reactions between objects and have them drift out of the playing field along the Z-axis. How can I do that?

Thanks!
Twig
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Best way to eliminate penetration?

Post by Norbo »

What's the best way to minimize that penetration? It's okay if it takes a few time steps, but the quicker the better.
The engine performs penetration correction by itself, so if it is given a few frames, the objects will push out to barely touching. You could weld the objects together at the first time of impact with a weakened, semi-springy weld. That way, the position correction system 'wins' and the object gets pushed out, but not too far. You can weaken a weld by changing the component constraint spring settings/maximum force.

You could also teleport the object on impact based on the contacts. The contact has a normal and penetration depth which you can use to push the object out immediately before welding.

Finally, you may also want to prevent the welded object from colliding with the player after it's been attached. You can do this using collision rules. More information about collision rules can be found in this documentation: http://bepuphysics.codeplex.com/wikipag ... umentation
My game is in 2D and I'd like to constrain all my game objects to a specific plane on the Z-axis. The main reason is because I don't want to accidentally cause reactions between objects and have them drift out of the playing field along the Z-axis. How can I do that?
The PointOnPlaneJoint would work. You can attach joints to the 'world' by passing in null for one of the connections. Internally, that connects it to a special static entity which represents the world.
twig314159
Posts: 7
Joined: Thu Apr 28, 2011 5:31 am

Re: Best way to eliminate penetration?

Post by twig314159 »

Thanks for the quick reply.
Finally, you may also want to prevent the welded object from colliding with the player after it's been attached.
I already did this. It worked really well. :)
You could also teleport the object on impact based on the contacts. The contact has a normal and penetration depth which you can use to push the object out immediately before welding.
I thought of this, I'm just not sure of the proper math to compute the right position. I'm sure I can find it somewhere, it'll just take some time to learn.

Thanks for the help!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Best way to eliminate penetration?

Post by Norbo »

Fortunately, it's pretty simple:

Code: Select all

AttachedObject.Position += contactNormal * contactPenetrationDepth;
The only tricky part is making sure the normal is pointing the way you want. It can technically point either toward the character, or away. You can calibrate the direction before use so it always points the way you want though; check out this thread: http://www.bepu-games.com/forums/viewto ... f=4&t=1163
Post Reply