Character Squeezing Through Wall

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
kokkivos
Posts: 19
Joined: Sat Apr 13, 2013 6:18 pm

Character Squeezing Through Wall

Post by kokkivos »

Hey there,

In my game, if I run straight at a wall and keep pushing, I can squeeze through it. My character controller is a cylinder, and my walls are static meshes.

I'm guessing this problem arises from me forcing the cylinder's velocity to the max speed every frame (when telling the character to move). Should I just add a sort of acceleration to the controller, instead of forcing the velocity, or is there a different solution I'm missing?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Character Squeezing Through Wall

Post by Norbo »

While collision constraints do have a tiny amount of softness to them by default, being able to push through a wall through setting velocity alone shouldn't be easy. For reference, in the demos, it takes a velocity of around 70 applied every frame to push a 0.6 unit radius cylinder through a wall.

If those are the kinds of numbers involved in your simulation, it is probably softness related. Some options:
-Setting CollisionResponseSettings.Softness to 0 would fix it, but nonzero softness helps stability in general.
-Leaving softness as is but setting CollisionResponseSettings.MaximumPenetrationRecoverySpeed to a higher or unlimited value may help. The velocity required to push through the wall in the above example rises to around 260.
-Leaving softness as is but setting CollisionResponseSettings.PenetrationRecoveryStiffness to a higher value, in conjunction with a higher MaximumPenetrationRecoverySpeed, could help too depending on the size of the objects involved. Going too far with either of these settings could introduce a lot of energy into collisions, like bounciness.

There are also some other possibilities if the failures are visible at speeds and sizes are not similar to the above:
-If things are much smaller or much larger, the default settings will not be well-tuned. Using the BEPUphysicsDemos ConfigurationHelper.ApplyScale function could help bring the tuning variables into alignment with the simulation scale.
-Is anything directly changing the position of the character? Changing the position directly amounts to teleportation, which velocity constraints cannot stop.

As a side note, using the actual CharacterController could help produce more robust behavior overall, especially when dealing with other dynamic objects. It's still possible to make it push through walls if its movement force is set sufficiently high and softness is present, though.
kokkivos
Posts: 19
Joined: Sat Apr 13, 2013 6:18 pm

Re: Character Squeezing Through Wall

Post by kokkivos »

Ah, I guess my numbers were just larger than BEPU expected. Using the code from the demo's ConfigurationHelper fixed the problem. Thanks!
Post Reply