- Home /
Enemy falls through floor when both have collider
I have a floor (complete with box collider not set to trigger) and an enemy (with a collider not set to trigger and a character controller). The rigidbody applies gravity to the enemy. The enemy, instead of falling and stopping at the floor like everything else in the room, falls straight through the floor into infinity. The floor's box collider is extremely thick (extends 100 meters below the 1 meter floor). The gravity of the enemy is minuscule (much less than one). I tried the "DontGoThroughThings.js" from the Unify community, with the floor set to a different layer. I have made sure that the enemies are well above the floor collider. I've been thinking through this and have searched through this site (my search yielded the Unify community "solution"), with the solutions that I found either something that I have already found or something that I have already tried. Does anyone have any idea of how to fix this?
Answer by Bunny83 · Jun 15, 2012 at 09:13 AM
Don't use a CharacterController AND a Rigidbody on the same object unless it's a kinematic Rigidbody. This doesn't work. Both components are responsible for moving the object. The Rigidbody is a physics object and the character controller is ment as a controlling component without being affected by physics, so you have full control over the character. You can't combine them. The CharacterController usually get it's own gravity applied in a script. Just take a look at the CharacterController-package that comes with Unity.
You have to decide which way of movement you want / need.
...This creates an odd problem. I need the character controller for the movement of the enemy - its the way its programmed, but I need the rigidbody for the collision events that it has... Should I use OnTriggerEnter ins$$anonymous$$d?
No, the CharacterController has it's own collision detection. See OnControllerColliderHit. If you need other moving things to collide with your player, they should have a rigidbody + collider. This way you get OnCollisionEnter if the other object moves into your character and if you move your character into the other object, you get OnControllerColliderHit and maybe OnCollisionEnter when the rigidbody is still awake.
I removed the rigidbody component and changed some of the collision events. It works better... The enemy still falls through the floor, but actually stops at some point. I think this would have to deal with the skin width... Am I right?
It could have to do with the position of your CC. Does it wrap the whole model?
Yes it does...and it isn't off-center from the model, either...
Since the parts of the model are off-center (including the collider), I re-positioned the model to where the center of the object parts was the "center" of the entire object. The model remains the same - except that the scale of the object jumps from 1 to 10! Any ideas?
...which should be in a different question. Removing the rigidbody did fix the problem addressed in this question.
Answer by zerox911 · Jun 15, 2012 at 09:00 AM
this is just a guess..
try positioning the object slightly higher(like y = + 0.5 / + 1.0) than the platform..
and when it fell.. note the position..
i had this problem before..
and..
its a wild shot to answer your question...
and i apologize if this doesn't work..
The enemy is already well above the floor... It ends up falling to about -.9 before dropping like a rock.
It usually is a good wild shot, @zerox911, so you don't have anything to apologize for. (I've had this problem before too.)