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
Best way to eliminate penetration?
Re: Best way to eliminate penetration?
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.What's the best way to minimize that penetration? It's okay if it takes a few time steps, but the quicker the better.
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
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.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?
-
- Posts: 7
- Joined: Thu Apr 28, 2011 5:31 am
Re: Best way to eliminate penetration?
Thanks for the quick reply.
Thanks for the help!
I already did this. It worked really well.Finally, you may also want to prevent the welded object from colliding with the player after it's been attached.
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.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.
Thanks for the help!
Re: Best way to eliminate penetration?
Fortunately, it's pretty simple:
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
Code: Select all
AttachedObject.Position += contactNormal * contactPenetrationDepth;