- Home /
First Person Controller not working with OnCollisionEnter and OnTriggerEnter
Hey everyone!
So I've been searching on for forums for similar problems but all I've found is unanswered questions. So here it goes: I've been making an FPS game and I want somehting to happen when the Character enters a room. So I created a collider on a decal which the character has to go through in order to get into the room, and after a few seconds the door should close.
I tried setting the decal into a trigger and used "OnTriggerEnter" in a script which is applied on the decal,didn't work.
I've tried expanding the radius on the FPS controller (the standard from unity) -> nothing.
tried to make the FPS controller into a trigger (with the help of a script) and tried to use "OnTriggerEnter" on the decal but failed there aswell.
I tried with OnCollisionEnter which also failed and resultet in no response
So what should I do?, what am I doing wrong?
Answer by mwebi · Jun 06, 2011 at 03:09 PM
You could try calling the void OnControllerColliderHit(ControllerColliderHit hit) function of the controller. http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnControllerColliderHit.html
But since i'm walking on a mesh that would mean that the function would be called several times. Guess I can solve it that way and check what it hit using tags. Just looking for a way to do it more efficiently
I use OnTriggerEnter for this purpose, and it always works fine to me. Have you set the Is Trigger checkbox in the collider? I usually put a cube, resize it and disable the mesh renderer, so it's invisible, and check Is Trigger. There's a small problem, too: if the trigger is too thin, nothing happens. It seems the Character Controller collider must "penetrate" the trigger volume a $$anonymous$$imum length in order to be detected.