Search Unity

Mesh vs Box Colliders (Accuracy)

Discussion in 'Editor & General Support' started by hai_ok, Oct 22, 2009.

  1. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    I have a 1.6 high 0.3 radius capsule collider, player.

    I have modeled a level, So I'm using mesh colliders.

    My player is a rigidbody.
    The player is slipping through the larger flat surfaces and also passing through the interior corners of my geometry.

    Would box colliders work better?

    It would be a LOT of work, but I'm considering adding invisible collision geometry (primatives) to the level to correct for this.

    Should I play with Solver Iteration Count?

    I've even tried adjusting the skin width:
    http://www.unifycommunity.com/wiki/index.php?title=DontGoThroughThings

    What Else can I do?
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    I would guess that the slip through happens because you move faster than the wall / your own collider is large ...
     
  3. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    I'm only going like 8 or 9.
     
  4. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    In Edit > Project Settings > Physics, try setting Min Penetration for Penalty to a lower value.

    Also, just out of interest, is the level geometry made of a completely enclosed volume or is it just a thin "skin", hollow underneath?
     
  5. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    @andeeee

    Will play with Min Penetration for Penalty.

    Ground is one sided plane with some variation, no fall-through there.
    Buildings are walls and ceiling with no enclosing floor. Is that the problem?
     
  6. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    WOW! I think that was the problem... May need to enclose the bottom of my geometry above the ground.

    Will Report on this asap.
     
  7. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    OK my buildings used to consist of several parts.
    outside
    ground floor
    2nd floor

    breaking them up like this was supposed to mean I could keep the 2nd floor ( the ground floor) turned off when out of range. I merged them together and enclosed the bottom of the mesh, and this APPEARS to have solved problem where the player passes through the middle of a wall.

    I'm still having problems with the corners.
    If you push into the corner even briefly, you will pop out the other side of the wall.

    My Min Penetration for Penalty is 0.0001
     
  8. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    Ok, narrowing it down to physical force.

    if I press one arrow key into the corner of an interior room, it doesn't pop through.

    pressing any combination of non-opposing keys into that same corner and the player pops right though.

    so the forward force and lateral force is being combined.

    This would appear to be the offending code:
    Code (csharp):
    1. function FixedUpdate () {
    2.     var translation = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")) * Time.deltaTime * speed;
    3.     transform.Translate(translation);
    4. }
    will post if I get this figured out. Lemme know if you have any ideas.

    thanks!
     
  9. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    It is generally not a good idea to set the position of an object (with transform.Translate or whatever) when it is under physics control with a rigidbody. This would almost certainly explain why your object sometimes moves through walls. If you add forces to move the rigidbody, you will usually get correct collisions, but you might also consider using a CharacterController instead of a rigidbody to control movement.
     
  10. hai_ok

    hai_ok

    Joined:
    Jun 20, 2007
    Posts:
    193
    I'm using things like explosive force and ragdolls. Unity is a physics centric engine.

    Don't I need a rigidbody?
     
  11. andeeeee

    andeeeee

    Joined:
    Jul 19, 2005
    Posts:
    8,768
    Well, Unity has a very good physics system, but it is very common to animate objects kinematically, too.

    If you want your characters to react to forces physically, then the physics engine is certainly the way to go, and you will indeed want a rigidbody on the object for this. However, to cooperate with the physics engine, you should move rigidbody objects using the rigidbody methods like AddForce, etc. If you set the positions of objects using transform.Translate, then you will often defeat the physics engine, because you haven't let it keep track of the objects' motion.