- Home /
CharacterController makes player game object fall through generated terrain.
- I have a player game object that uses CharacterController. 
- I generate my terrain from script when the scene is loaded (scene already has player game object) 
- Problem: Player GO falls through terrain while everything else stays on it. 
- other game objects with rigidbodies act as they should (colliding and bouncing on terrain, falling downhill slopes, etc.) 
Every aspect of the terrain is complete, with a proper terrain collider and splatmaps/details. I also generate a navmesh and it works properly too (scripts generate stuff on random navmesh points, etc).
Further info:
- The player GO is located where it is supposed to be, not intersecting the generated terrain's collider. 
- I tried both with player GO having a rigidbody ant not. (I know it's not supposed to have one anyway) 
- I tried in vain adding a capsule collider to a GO. 
- Player GO does not fall through the terrain if I have an existing terrain on the scene and modify it; instead of generating the asset in memory and adding it to the scene. 
Can anyone give me some advice? I have searched all through and tried everything I could think of (short of changing the CharacterController with a RigidBody setup - which would be very, very, problematic at this point.)
I have debugged a lot more and came to the following conclusion: CharacterController does not collide with the generated terrain collider (`OnControllerColliderHit` is not called) but it collides with any pre-existing colliders in the scene (e.g. if I placed a plane under it). How can I get them to collide?
Answer by LouskRad · Sep 02, 2017 at 01:24 PM
I figured this out, and in case anyone faces this issue, here is my fix/hack:
The problem was, for some reason, CharacterController did not register the TerrainCollider that I was creating through script. Since it was registering this if I used an existing terrain and modified it, it occurred to me that I should maybe try disabling and re-enabling the created TerrainCollider after I had finished with creating the terrain. It worked - CC now properly collides with TC and the player GO does not fall through. Simply:
 _terrainCollider.enabled = false;
 _terrainCollider.enabled = true;
Note that I believe this is a hack used as a workaround for a bug in the CharacterController. (or at least its integration with the TerrainCollider
Your answer
 
 
             Follow this Question
Related Questions
NPCs fall through hills in terrain 1 Answer
bullet collision with Terrain and Character Collider doesn't work in very fast speed 2 Answers
Ship and terrain collision.Need help. 1 Answer
How does unity character controller work? 0 Answers
How to fix the position of a character when grabbing a rope? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                