2
votes

I have a character with compound collider setup (the collider that is setup by many primitive collider shapes, one for each body parts), and a simple ground that is setup using a scaled cube. The cube is scaled 1000 in x and 30 in z axis. Things are still in early stage, so there is no expensive graphic, there are just primitive shapes and a low-poly character in scene. Things are going fine at begin, but for some time, after I play for a while, the character start falling through the ground. Anyone has encountered this problem and know how to fix this?

1
This happens most often when you fall between the cracks on badly modeled/joined terrain (due to floating point rounding errors). If your "floor" really is a single solid object, the next thing I'd check is that the physics loop is running at a high enough frequency that the player can't fall too far into the object before the next tick. Failing all of the above, I'd make your collider slightly larger.Basic
My Fixed Timestep is 0.02, Max Allowed Timestep is 0.3333333, which are still default value. Is it ok? And I also realize that this seems to be happen only when I play an animation with high playback time, the playback time of that animation is set to 3.congtrungvnit
As you suggest, I have adjusted the Fixed Timestep to 0.002, which is 10 times faster. Things seems to be better. But is it ok for CPU? As I've heard that decrease this value will have impacts on CPU performance. What is you recommended value? And btw, do you try this solution? (answers.unity3d.com/answers/1244965/view.html). I have tried but it does not work.congtrungvnit
That link is broken for me (Access denied). I've had problems with (scripted) animations before where I've been using a float to track elapsed time. As the number gets higher, precision drops so the animation became "jerky". Not sure fi this might be an issue in your case. I believe you're more likely to get good results if the surface is thick enough that you can't clip thoroughly it properly. Re: TimeStep, I'm afraid there's no right answer. It's a balance that depends entirely on your game, however, if you're still getting issues it sounds like low TimeStep might just be masking the problemBasic
Yeah, I've increased it a bit to 0.005. The problem doesn't happen right now. Hopefully it will never occur again in the future, as I have spent nearly my whole day for this problem @@. Btw, there is a recommend that I should set physic material for my character, but I think it is not necessary. I think if I do so, the physic engine will wastes resource to calculate friction, bounciness for my character, which is not necessary for mine, right?congtrungvnit

1 Answers

2
votes

Here is a good reference-list of possible reasons by SisterKy.

Check each Object involved (FallingObjects and GroundObjects)

  • Does Object have a Collider? If not,

    1. select Object
    2. go to the top bar
    3. components
    4. physics
    5. choose appropriate collider (if Terrain, check the last tab, the little cog-wheel)
  • Note: mesh-collider may cause problems.

    • Particularly, if both FallingObject and GroundObject have mesh-collider.
    • Particularly, if the mesh is animated.
    • To avoid mesh-collider, you can build an aproximate shape of your mesh from several primitive colliders (in parent-, child- or sibling-GameObjects).
    • If you need a Mesh-collider no matter what, you can try to place additional primitive colliders where they won't be in the way to 'enforce' the collisions.
  • Is the Object a Trigger? If so,

    1. select Object
    2. find its Collider-Component (if Terrain, check the last tab, the little cog-wheel)
    3. remove the check of 'IsTrigger'
  • Is the Collider placed well? fiddle with center, size and skin-width (start with 0.1) until the green outline aproximately fits the character (If you get really strange values, it might be due to scale (e.g. your mesh was way too big so you downsized to .01))

    You may try to zero out all positioning (both unity and your modeling-program)

FallingObject and GroundObject have a problem with each-other

  • FallingObject-Collider and GroundObject-Collider intersect each other.
    Move the Object much above the ground (have it fall from some considerable hight for test-purposes).
    All of it! Not just the collider or something else that is attached to it (e.g. the Camera of a Character Controller)
    Note: a poking-through ("grey capsule"?) may cause Problems even if it's disabled. (I am not sure what that means myself, I'm sorry... the answer that posted this solution was not very specific =/ )

Imported Objects (.obj, .fbx, .max etc.)

  • Before dragging Object into the Scene (delete if already there),

    1. Look at the hierarchy
    2. find the model
    3. properties
    4. check 'Generate Colliders'
    5. hit Apply
    6. now drag to the scene
  • Are the Normals correct? You may have to

    1. go back to your modeling-programm
    2. hit flip/reverse Normals
  • Is the Mesh clean?
    Reportedly a single 2-vertex-"triangle" caused bad collider-issues.

  • Geometry is rather complex? Then you need the Mesh-Collider set to convex

    1. Select Object,
    2. Mesh-Collider-Component
    3. check 'IsConvex'

FallingObject has a Character-Controller

  • Is a Rigidbody applied? If not,

    1. Select the falling object
    2. Top bar
    3. components
    4. physics
    5. rigidbody
  • Is Gravity applied? If not,

    1. Select the falling object.
    2. Find its Rigidbody-Component.
    3. Check 'Gravity'
  • And has a MouseOrbit?

    Make sure MouseOrbit never has/picks up any parent of the respective object that MouseOrbit is attached to (usually the Camera) as MouseOrbit-target or the resulting 'dog-chases-tail'-scenario will cause falling. http://answers.unity3d.com/questions/161386/third-person-controller-falls-through-terrain-upon.html

GroundObject is a Terrain

  • Rumor has it, that Terrain Collider may be screwed up by using the terrain toolkit asset package to make the terrain.

  • Collisionmatrix may cause trouble.

    1. Go to Edit/Project Settings
    2. Physics
    3. collisionmatrix

Scripts

  • FallingObject has a script with 'transform.Translate' or 'transform.position = ' or various other 'funky' scripting.
    This may push the Object through the collider 'against its will'. Try to avoid it. (e.g. use 'velocity' or try SimpleMove)

Keep your scene clean

especially the mac-version seems to be a bit buggy when faced with too much superfluous crap. may somehow disable all colliders.

Debug

  • Increase physics calculations per frame.
  • Try and catch collider penetrations (this doesn't solve the source of the problem).
  • Drop the Character and a default Cube from high up.
    • If both fall through, investigate the floor's properties.
    • If only the character does, investigate the player's properties.
  • Sometimes good old restart or reimport might just do the trick...
  • You may want to try Debug.Log(colliderFlag); to check, if it's really not touching. http://unity3d.com/support/documentation/ScriptReference/CollisionFlags.Below.html

Note

Falling occures when minimizing or alt-tabbing the editor.

This is a known issue; don't worry about it too much, it's only in the Editor and won't happen in the final-built game.

Please Note: I have no competence on the matter what so ever... just gathered what I found. So please point it out if you find any (severe?!) mistakes.

my sources:

http://answers.unity3d.com/questions/39789/tornadotwinswormvideo2-help.html

http://answers.unity3d.com/questions/17779/character-model-sinks-through-floor.html

http://answers.unity3d.com/questions/31397/object-falls-through-floor.html

http://answers.unity3d.com/questions/31033/items-falling-through-floor.html

http://answers.unity3d.com/questions/29719/falling-through-the-floor-issue.html

http://answers.unity3d.com/questions/43206/falling-through-floor.html

http://answers.unity3d.com/questions/35010/my-object-falls-through-terrain.html

http://answers.unity3d.com/questions/8369/whenever-i-run-my-game-i-fall-through-any-terrain.html

http://answers.unity3d.com/questions/21021/enemies-fall-through-floor-when-chasing-player.html

http://answers.unity3d.com/questions/17221/char-is-falling-through-the-terrain-when-alt-tabbi.html

http://answers.unity3d.com/questions/63750/my-characters-and-rigidbodys-fall-on-my-new-terrai.html

http://answers.unity3d.com/questions/57077/character-collider-physics-bug-in-unity-33-falling.html

http://forum.unity3d.com/threads/38996-first-person-controller-falls-through-the-terrain