- Home /
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?
related: http://answers.unity3d.com/questions/55179/cheapest-way-to-catch-collisions-on-very-fast-movi.html - and by the way, your forgot to give us a link to your game! or at least a trial. :D
Answer by iggy · May 31, 2011 at 09:30 AM
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: http://unity3d.com/support/documentation/Components/class-Rigidbody.html
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
Thank you for the answer, it does work, but i may just alter my level designs to remove the ability to free fall for so long :)
Answer by Kacer · May 31, 2011 at 09:53 AM
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.
Answer by save · May 31, 2011 at 09:43 AM
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
Tried to edit the above but then I accessed the actual html, didn't dare. :) Just wanted to say that there's also good practice to have a maximum velocity limit of important rigidbodies.
yes, that could work too, casting a Ray to check if there is ground below or something like that.
Answer by cregox · Sep 27, 2011 at 06:12 PM
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.
Your answer
Follow this Question
Related Questions
Have script detect which collider 2 Answers
Player(box) randomly falls through objects. 1 Answer
How to Move Player in Particular Direction Without holding Down a Button? 0 Answers
OnTriggerEnter2D not triggering 2 Answers
I am getting player tag not the other object that i want to destroy. 1 Answer