- Home /
OnTriggerEnter with the character controller collider
So I've made a player with a character controller, and no other collider. I am trying to use the function "OnTriggerEnter" or "OnTriggerStay", but it doesn't seem to work with the character controller.
Does anyone have any idea as to why? Or maybe what else I could do
Answer by carlqwe · Mar 27, 2016 at 03:37 PM
Make sure that the collider that is attached to the script object is tagged as "IsTrigger"
And if it doesn't work try something like this:
function OnTriggerStay (Col : Collider)
{
if(Col.tag == "Player")
{
//Do magic
}
}
Attach it to the gameobject that has the collider set to "IsTrigger" And be sure to tag the player as "Player"
If it doesnt work post some pictures and explain more what is happening
~carlqwe
Answer by meat5000 · Mar 27, 2016 at 01:37 PM
There is this method
http://docs.unity3d.com/ScriptReference/CharacterController.OnControllerColliderHit.html
for collisions on CharacterController.
I notice in the docs, under 'Inherited Members' that "isTrigger" is actually listed. Perhaps this will actually work to change the CC collider to a trigger? May cause problems, who knows, you can but only try.
The thing is, I am using a character controller - not a rigidbody
Answer by giorashc · Mar 27, 2016 at 01:23 PM
In order for an OnTrigger...
event to occur your game object (player) must have at least one collider (marked as trigger in your case). So attach a collider component to your player (or character controller) depicting the area which will cause a trigger (and mark the collider as trigger in the inspector)
can you post the player hierarchy and the inspector content? are you sure you have a collider on your play/controller and that the other game object (the one you expect a collision with) has a collider as well?
It turns out the trigger was too small - even though it did touch the buttom of the player. That was the only problem. Why this occoured? I don't know, but it did - But it's fixed now :D
Answer by xTyler73 · Nov 18, 2018 at 08:11 PM
By default, colliders are set to the same size as as the object you add it to, so the trigger could end up being inside the object. You'll need to offset its "Center" property so that it's big enough to actually collide with the player without being too small.
Just realized the answer is here in a reply, but not marked as the best answer so I missed it on my first reading. Hope this helps someone.
Your answer
Follow this Question
Related Questions
Destory/Collect object to open door 1 Answer
Using two trigger colliders 1 Answer
Trigger help! 0 Answers
Multiple Cars not working 1 Answer
Adding force relative to the distance from an object 1 Answer