- Home /
The question is answered, right answer was accepted
Character controller not colliding with enabled box collider
Hello,
I've not been able yet to make this work so here it goes.
Is there any possibility to make a Character Controller Collider well collide with another object that has a Box Collider with IsTrigger enabled?
I've already tried creating children empty gameobjects and that doesn't fit the purpose of my problem right now.
My problem is really happening because I want my other GameObject to collide with a wall. Therefore I've enabled its trigger and added a rigidbody. Problem is now my AI won't make contact to it (just passes right through).
Any advice would be greatly appreciated.
Answer by MSB · Jun 15, 2013 at 02:16 PM
The easiest way is to have 2 copies of the wall, first one is solid, the 2nd one is the trigger with the render turned off on it. So, duplicate your wall with its trigger, for example, call one "Wall" the other "Trigger" and put them in the same space. Ensure that "Trigger" has "istrigger" turned on and it's "mesh render" turned off. "Wall" has "istrigger" turned off and "mesh render" turned on (and a collider)
You then increase the size of "Trigger" a tiny bit to make sure the gameObject can make contact with it whilst it hits the rendered, psychical wall. Also you can drag "Trigger" onto "Wall" to make it a child and keep it organised.
Hopefully that makes sense!
Ah just noticed you said you had tried empty game objects. The moment you make something a trigger it will lose the psychical collider. This might be of use though http://www.unity3dstudent.com/2010/07/beginner-b01-basic-collision-detection/
(Sorry I'm typing all this on my phone, it's a bit slow)
If you try this
http://www.unity3dstudent.com/2010/07/beginner-b01-basic-collision-detection/
You can detect collision whilst keeping the colliders with them not being triggers.
@$$anonymous$$SB marking as right question. It was my problem, I was simply said, scratching me left ear with my right hand...:) Thanks
Answer by PAHeartBeat · Jun 15, 2013 at 12:25 PM
if you add Character controller component on you object, it's should not detect collison or trigger using OnCollisionEnter or OnTriggerEnter function, use
void OnControllerColliderHit(ControllerColliderHit hit) {
}
method instead.
I'm already doing that. $$anonymous$$y problem is only with the other gameobject (let's call it "cube"). So my Character Controller passes through my cube(which is trigger enabled) but collided perfectly with all other objects in the scene (which have the difference of not having their triggers enabled).
No, When your cube collider or any other collider has IsTirgger enables, it's Pass through out the object, it will not stop when its collide with the object, if you want to stop your character when it's collide CUBE, you need to set Trigger disabled.
That's why I asked the question. I need that object to have the trigger enabled because its and instantiation and it will instantiate itself non-stop until it collides with something, if i would disable the trigger, then the item will continue to instantiate. The problem is a bit more complex I fear.
I Think you use OnTriggerEnter()
method for detection of collision, am I right?
if Yes just Use OnCollisionEnter()
method and put trigges as disabled. Once it's get collision info in OnCollisionEnter()
$$anonymous$$ethod you can stop instantiation for further.
I don't know exactly how and what purpose you use OnTriggerEnter()
method. if you can share you small part of code so we will help you further solution.
Follow this Question
Related Questions
CharacterController unexpected collisions with MeshCollider 0 Answers
More realistic physics? 0 Answers
Character controller partially passing through rigidbody in a head on collision 2 Answers
OnCollisionEnter not working with CharacterController 1 Answer
Colliders going through Colliders? 1 Answer