# Character controller passes through mesh collider

I need a little help figuring out what's going on with an NPC's character controller. Here are the character controller settings for the NPC.

The problem I'm running into is that the NPC isn't walking up a slight gradient as it should; instead, it moves through the ground.

Below are the settings for the ground.

The NPC isn't on the ground- it is a few units off. Any help is greatly appreciated.

• Do you have a collider and a rigidbody controller on your player? Do you have a rigidbody collider on your terrain? – Honeybunch Jul 29 '15 at 21:17
• Yes, the 1st image is the NPC's character controller which has similar settings to the player's character controller. I tried using a rigidBody for the NPC but it was still doing the same thing. The image below is the the ground's mesh collider. Just to test, I added a kinematic rigidBody to the ground & the NPC is still behaving the same way. – Mark Laurel Jul 29 '15 at 23:25
• Are you sure that both colliders fit exactly to the shape of the objects? – Vadim Tatarnikov Jul 30 '15 at 7:18

Use a raycast or this script. http://forum.unity3d.com/threads/groundnpc.181705/#post-1241872

Don't add a Rigidbody if you use the controller. It breaks it big time.

And check off convex on the mesh collider for your terrain. Try this first before adding a script. I remember having this problem before and that's all it took.

• I updated & used the script from the link you posted. It works brilliantly! Thank you. – Mark Laurel Jul 30 '15 at 13:40

This is an update to a script found here:

This is a simple fix that prevents NPCs from walking through sloped mesh.

#pragma strict

var gravity = 20.0;
var verticalSpeed= 0.0;
private var collisionFlags : CollisionFlags;  // The last collision flags returned from
// controller.Move

function Update()
{
ApplyGravity();

// Calculate actual motion
var movement = Vector3 (0, verticalSpeed, 0) + Vector3.zero;
movement *= Time.deltaTime;

// Move the controller
var controller : CharacterController = GetComponent.<CharacterController>();
collisionFlags = controller.Move(movement);
}

function ApplyGravity()
{
verticalSpeed = IsGrounded() ? 0.0 : verticalSpeed - gravity * Time.deltaTime
}

function IsGrounded()
{
var controller : CharacterController = GetComponent.<CharacterController>();
return (controller.collisionFlags == CollisionFlags.Below);
}