- Home /
Can someone please explain Character Controller use?
I've read all the documentation and answers here about it, and I still don't really get why this doesn't work...
I have a character who I need to move locally with Character Controller, and remotely by just setting its transform (thru my own serialization code). Both use the same prefab, but in Start() I disabled the character controller if the player is a remote player.
When I do that, I don't get my trigger collision events activated by the player. This is even though I also have a mesh collider and kinematic rigidbody on it. It only works if the (unused) character controller is active.
Is the controller somehow disabling the collision that should occur with the separate collider? Or since the mesh collider is a child of the character controller's object, does that make it stop working? Or do I really not understand how Unity physics is designed (most likely answer)?
Answer by Kiloblargh · Feb 07, 2014 at 02:04 AM
If you used gameObject.SetActive (false) i
t will also make any children inactive. component.enabled
will not.
Your problem is probably not with the CharacterController's collider but the mesh collider. The mesh collider needs to be convex, and it should have the correct layer / tag.
A Debug.Log message will let you know if the mesh collider is ever sending trigger enter events at all.
To explain the Character Controller's use: Its main use is for beginner FPS tutorials to make it look as creating controllable characters in Unity is easier / more user-friendly than it really is. If you are making a real game, at some point you will realize you can't make a Character Controller do everything you want it to do and you're going to have to write a custom script to replace it.
Yeah I still don't get it. I understand what you say about "easier than it really is" but if underneath the CharController is just setting the transform, shouldn't it trigger for local and remote players (if the remote player is me setting the transform manually)?
Yeah I used debugging, the first line of my Pickup.OnTriggerStay (started using Stay ins$$anonymous$$d of Enter, just to be sure) just had Debug.Log("trig") and when I move over it with the local player the console spits out trig, when I watch a remote player move there nothing happens at all.
Both players come from the same prefab, and I've manually checked the editor to see their Layers and Tags are the same.
Yup I was just disabling the component, so according to what you said that shouldn't affect anything. And yet...
Since posting I found out that if I set everything up as described before, but I DON'T include the line "GetComponent<CharacterController>().enabled = false" the trigger DOES occur. Since the object being triggered is the pickup, shouldn't the dwarf's collider trigger it no matter what the CharController is doing?
I fixed the issue that made me start disabling remote character controllers, so it works now, but I would really love to know why?
(With your comment about convex colliders, I may have a hypothesis. I thought I was using the default Colliders unity puts on certain prefabs, like a box collider, but actually its a mesh collider using the built-in primitive cube. Likewise the coin uses an icosphere mesh collider, and mesh colliders are not created with the convex checkbox checked. I remember two non-convex meshes won't collide, at least not without more work. So maybe I just didn't realize there were different types of colliders, and I can change both and have it working!)
(Edit: That was it! I initially created Quads which come with $$anonymous$$esh Colliders by default. Changing them to Box and Sphere Colliders has fixed everything. Thank you so much for the insight!)
Your answer

Follow this Question
Related Questions
Character Controller's performance for massive groups 0 Answers
Prevent physics judder in an elevator/moving vertical platform? 1 Answer
Question regarding character controllers and slopes 0 Answers
2D 360 degress platformer example needed 0 Answers
Rigidbody physics behaving differently from editor to build 0 Answers