- Home /
Triggers not working
I'm having an issue getting my trigger to work. I'm using a character controller on my player but it isnt getting detected when I collide. I marked the object as a trigger and named everything correctly. Something must be wrong here. I believe the controllerCollider is the thing it can't find mabye ? I get no errors.
function OnControllerColliderhit (hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "triggerloadbarracks")
{
}
A trigger ONLY gets the message that something hit if and only if the other object has a non-kinematic RIGIDBODY attached. A character controller is not a rigidbody. A character controller is a collider.
so what exactly should I change to get this to function ? haven't worked with triggers enough.
@SilverTabby You're talking about collisions, not triggers. A trigger event is sent as long as one of the colliders is a trigger and one of them is non-static.
Answer by aldonaletto · Jun 23, 2011 at 09:09 PM
A trigger reacts to Character Controller and/or rigidbodies. The problem is that you're using the wrong event - for triggers use OnTriggerEnter:
function OnTriggerEnter (hit : Collider){
if(hit.gameObject.tag == "triggerloadbarracks"){
// do whatever you want here
}
}
hmmm just tried this code and nothing seems to be happening either..
I used this same code in a test script and it worked fine! Have you checked the usual suspects? 1- tags are case sensitive, so triggerloadbarracks is not the same as TriggerLoadBarracks ;
2- tag and name are different things: to compare names, use hit.name == "johnSmith" or whatever name the object has.
I suggest you to test different cases: remove the if and check if the onTrigger works; if it's ok, try a name ins$$anonymous$$d of the tag
NOTE: There's one more thing to check: when the trigger collider is too thin, the character controller may not fire it - it must penetrate the trigger a little to be detected. Try to fatten the smallest dimension to at least 1 to check this possibility.
This is javascript correct ? I've checked all the na$$anonymous$$g conventions and everything, changed the size and such too. I'm just not sure wat exactly I'm doing wrong. Wonder if collider is an issue or if theirs a way to change that, mabye its not detecting my character controller colliding with the object.
Have you tried just the OnTriggerEvent without any other conditions? $$anonymous$$ind of:
function OnTriggerEnter(hit:Collider){
print("Hit");
}