- Home /
Character collider / physics bug in Unity 3.3 - falling through terrain / objects
I am working on a large 3rd person game project in Unity. We started in 2.6 and everything was working great. When we upgraded to Unity 3.3, we started to have an issue where the player, at seemly random times would just fall through the world. The funny thing is that when this happened, not only the player would fall through but other NPCs (with Character Controllers on them) would do the same at the exact same time.
When running in the editor, I would pause, raise the player and other NPCs above the terrain and hit play again. The player (and other NPCs) would then just keep falling, right through the terrain (both Unity terrain and externally modeled objects with mesh colliders.) If I manually put a cube or plane below the character with the standard colliders it stops as it should. It is almost as if Physics/colliders completely broken between the character controller and the terrain (or externally modeled terrain with mesh colliders) in the game.
I read some other posts that said you should delete the character controller and re-add it after upgrading to Unity 3. I did this but the problem still persists.
To be clear, the player works fine 95% of the time. The other 5% it just falls through the world (as described above.) Unfortunately we have burned 40 hours trying to diagnose and solve this problem. I am 99% certain that the issue is with Unity itself and not our setup or code.
We need to resolve this ASAP as we need to release the game. Any help would be greatly appreciated.
UPDATE: The problem seems to happen more often when we delete game objects with colliders on them. For example, we delete arrows that have been shot after a period of time. Deleting these colliders seems like it may be causing holes in the terrain mesh collider. Very strange...
You may have to use the bug reporter. Go to help ~> report a bug (which is right at the bottom)
I've found Unity to have numerous issues with mesh colliders. In most cases I find using box and other simpler colliders tends to solve the problem. But in most cases this is not feasible :(
I've been experiencing a similar problem. I'm developing a game in my notebook, and when the frame rate falls to a ridiculous level (3 fps or less) something strange happens. First, some coins - simple objects with spherical colliders - start to be "taken" by the player - but the player is stopped far from them, and it should only happen if an object named "player" entered their colliders. A few seconds later, the player itself falls through the ground.
It's not an experience directly related to Unity and its colliders, but I've seen this same behavior before. In my case, it was a simple terrain mesh and some characters and NPC would just fall through, see$$anonymous$$gly randomly. The culprit was a 2 vertex "triangle". I'm not sure why exactly, but the code we were using didn't like it.
I'm not sure if Unity collision works even remotely similar, but its worth taking a look at your mesh(s) for lines and ngons.
I'm getting a very similar problem - especially the infrequency of it (things that collided fine suddenly do not), and I hide and show (via GameObject.active).
Interestingly though, all my colliders are primitives - mainly BoxCollider.
Answer by gordieross · Nov 10, 2011 at 08:33 AM
I think this has to do with the slope limit.
When something collides with the Controller capsule, the capsule thinks it is another platform.
I fixed this problem in my game by adding tags to the things I didn't want the Player to treat as a slope.
If the player collides with any of them, I set the Slope limit to 180 degrees, else I set it back to the original value in the script.
That seems completely unrelated. Are you saying that without such action, your characters fall through or penetrates those objects? If so, can you explain how slope limit effects it? If not, could you please delete this answer. Hopefully it is the former and we are onto a solution.
$$anonymous$$y understanding is that slope limit either stops objects (too steep) or lifts them (up slope). Never does it make objects non-collide.
Answer by gordieross · Nov 10, 2011 at 11:19 AM
When I have terrain beneath my Character Controller capsule and it bumps into a sphere above it, it momentarily seems to ignore the fact that it is still colliding with a target below it.
I've fixed my problem where my CharacterController was falling through the terrain by adding to the OnControllerColliderHit function in PlatformerController.
function OnControllerColliderHit (hit : ControllerColliderHit)
{
if (hit.moveDirection.y > 0.01)
return;
// Make sure we are really standing on a straight platform
// Not on the underside of one and not falling down from it either!
if (hit.moveDirection.y < -0.9 && hit.normal.y > 0.9)
if (hit.collider.tag != "Ball")
activePlatform = hit.collider.transform;
if (hit.gameObject.tag == "Ball"){
if ((controller.transform.position.y-(controller.height/2)) < controller.collider.transform.position.y){
controller.slopeLimit = 180.0;
}
}
if (hit.gameObject.tag != "Ball"){
if (controller.slopeLimit != 45.0)
controller.slopeLimit = 45.0;
}
}
Without seeing the source code relating to CharacterController I can't tell what exactly is going on, however this solution works in my case. If it is deemed not to be useful comment, then I will surely remove the posts.
Answer by stu · Jan 05, 2012 at 05:42 AM
I have a similar problem where, if I do something to one object (say add a collider, but no rigidbody) collision detects breaks for everything. No errors show up in the console window, nothing. If I revert the change, all of the sudden, everything starts working again. Right now I'm fighting with trees.. as soon as I add a capsule collider to my tree pre-fab, everything breaks. Remove it, and it's fine.
Sorry I can't help with an answer, but this definitely seems like an issue with Unity. Even if I'm/we're doing something wrong to one object, it should not:
silently hide any errors
break other, completely unrelated, objects
There must be something causing a singularity in the physics calculations or something.
$$anonymous$$y "fix" was to use less colliders, and perhaps adding the collider to your tree prefab means you have a lot of colliders. Still definitely a bug in Unity of course (if it was at least numerically documented and gave an error/warning they could call it a limitation).
Answer by hay78 · Nov 11, 2013 at 10:00 PM
Sorry to ressurect old thread, but hoping that someone could tell me how you solve this issue as i am also experiencing the same problem as OP. I have 2 jungle scenes with quite a lot of trees, plants and rocks. The avatar/player and animals that both has character controller would just fall down the terrain(mesh model from 3DS Max)at any random time. And animals are using NAV mesh A-Star pathfinding. It didn't happened before with just the avatar and 3D environment. But as soon we added/modified more stuff (eg: add quests and animals with pathfinding, change avatar system to mecanim). We have 2 other environments, which is just interiors, and they are fine. And this issue only happened in player, Not in editor
This is old, I know, but I have this very same problem with 4.3. Trying to find a solution...
Answer by kapytanhook · Jan 13, 2014 at 04:42 PM
We found a solution in our case for this same bug that was killing us for a month. We had a dude with just a charactercontroller attached to him and a script to move it
All layers where correct
Terrain collider was correct
We never move him using transform.position but always charactercontroller.move
Yet randomly after a few minutes to hours it would just stop working (even ray casts preformed from that gameobject would stop working).
Then we attached a kinematic rigidbody not using gravity to the same gameobject as the charactercontroller and all of a sudden the bug stopped showing up. Even though it should be completely unrelated somehow this fixed it for us.
(also a very important note, do not change properties of the charactercontroller at runtime like slope limit, width and height, that gave us very unpredictable results).
Hope it will do the same for you. Cheers.
We managed to fix the issue by adding rigid body /character controller to the animated animals (as they move around in jungle). They only had primitive colliders before which are basicly just static colliders. And this prob cause the character/animals falling down.
As stated in the unity manual documentation below: http://docs.unity3d.com/Documentation/$$anonymous$$anual/Physics.html
Colliders can be added to an object without a Rigidbody component to create floors, walls and other motionless elements of a scene. These are referred to as static colliders. In general, you should not reposition static colliders by changing the Transform position since this will impact heavily on the performance of the physics engine. Colliders on an object that does have a Rigidbody are known as dynamic colliders. Static colliders can interact with dynamic colliders but since they don't have a Rigidbody, they will not move in response to collisions.
Cheers
Grats on fixing your issue, i actually read that page too. "they will not move in response to collisions."
That is the behavior I want, the character controller has a .move function property. And like i said it works for hours on end sometimes.
And if you read the unity documentation for character controller: http://docs.unity3d.com/Documentation/Components/class-CharacterController.html
"The traditional Doom-style first person controls are not physically realistic. The character runs 90 miles per hour, comes to a halt immediately and turns on a dime. Because it is so unrealistic, use of Rigidbodies and physics to create this behavior is impractical and will feel wrong. The solution is the specialized Character Controller. ..... On the other hand, if you want your player character to be affected by physics then you might be better off using a Rigidbody ins$$anonymous$$d of the Character Controller."
So they really indicate you can use rigidbodies OR charactercontroller.
So yeah I don't think every person encounters the same issues as we did. Thanks for your response.
Your answer
Follow this Question
Related Questions
character gravity problem 1 Answer
Falling through ground with colliders 10 Answers
New to Unity, trouble with physics it seems! 3 Answers
Lunging with Character Controller 0 Answers
Irregular ground collision 1 Answer