Mesh vs Box Colliders (Accuracy)

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:

What Else can I do?

I would guess that the slip through happens because you move faster than the wall / your own collider is large …

I’m only going like 8 or 9.

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?

@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?

WOW! I think that was the problem… May need to enclose the bottom of my geometry above the ground.

Will Report on this asap.

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

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:

function FixedUpdate () {
	var translation = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")) * Time.deltaTime * speed;
	transform.Translate(translation); 
}

will post if I get this figured out. Lemme know if you have any ideas.

thanks!

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.

I’m using things like explosive force and ragdolls. Unity is a physics centric engine.

Don’t I need a rigidbody?

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.