Character Controller OnControllerColliderHit and Triggers

Hi all,

I currently have a Character with the following properties:

  • Character Controller
  • Capsule Collider
  • Generic Move/FPSInput Scripts

This character is running across a platform of Cubes and detecting when Off and On the Cubes. I’m having a few problems:

  1. I can use OnControllerColliderHit to determine when the Character is on an Object but not leaving

  2. If I use OnTriggerEnter/Stay/Exit on the Cubes to determine when leaving the character falls through the Cubes (I tried using a Convex in Mesh Collider, didn’t help?)

  3. Adding a Rigidbody to the Character sends the character spinning in multiple directions… some would way dancing.

I’m sure there is a correct way but I’m just not approaching it… help appreciated.


You can do this with collider. Parent a child object (rigidbody) with its own collision layers and its own collision handlers that communicate with your avatar scripts (telling it on what ground it stands)
However the “correct” method would be to use Physics.Raycast() and constantly shoot a ray downwards from your avatars position. The RaycastHit can tell you what is below you: From there you can access pretty much anything (Tags, Materials, GameObject…).

You will still have to write a function that registers when the specific (object, tag, material, etc) of the RaycastHit has changed.

Hope that helps!

Thanks Broheim (cool name haha), RayCast works like a charm.