Player falling too fast for a collider to stop it

Hello,

I have a little problem where if i let my character fall for too long, and they are going to collide with an object that is a tree branch for example, i would like the character to stop, but they seem to always fall through the collider. I understand that this may be caused by the fact that the character is falling too fast, but is there a possibility to be able to stop the character from falling through objects?

Well the easiest way i can think of if you set your important rigidbodies to “Collision Detection → Continuous”

Continuous

Use Discrete collision detection
against dynamic colliders (with a
rigidbody) and continuous collision
detection against static MeshColliders
(without a rigidbody). Rigidbodies set
to Continuous Dynamic will use
continuous collision detection when
testing for collision against this
rigidbody. Other rigidbodies will use
Discreet Collision detection. Used for
objects which the Continuous Dynamic
detection needs to collide with. (This
has a big impact on physics
performance, leave it set to Discrete,
if you don’t have issues with
collisions of fast objects)collisions of fast objects)

Source: Unity - Manual: Rigidbody component reference

Edit: now that i think of it, it probably won’t help when player is moving fast, only when Rigidbody is moving fast. So if you character has Rigidbody you can set its Collision Detection to Continuous or if it uses Character Controller you can limit the Fall Speed with setting “Drag” > 0

you could also use a raycast to see if you’re near a collider, and tell your object to stop when you get too close to the collider.

As iggy said all important objects should have Continuous or Continuous Dynamic collision detection. But when an object reach a certain magnitude the calculations won’t keep up anymore as the object is moved past the collider with no step in between.

You could use check for distances and height to a collider beneath. Then if that distance is <= collider-xz size and falling object <= colliders transform.position.y, apply the same force the rigidbody has in the downward direction to the upward direction * bounce.

Adding to iggy’s answer, DontGoThroughThings is what you need. Raycasting is the idea, though not quite the way Kacer pictured. It basically checks if it crossed any object between two frames in which the player moved too fast.

It sure worked in my case, in which I had several objects in the scene at the same time that would kind of “explode” and should be contained inside a box. To me, it was as easy as adding the script to those objects.

Yes, that also worked for me, Thank you! :smiley: