- Home /
trigger not triggering
I have a sphere trigger as a child of a game object who has an animation attached.
the idea is to have the user walk into the trigger and it tells it's parent to play the animation. but its not playing. I don't get it. here's the code that is on the Sphere trigger:
function OnTriggerEnter (other : Collider)
{
transform.parent.animation.Play("MyAnimation");
}
$$anonymous$$ight be obvious, but are you bringing in the "other"? $$anonymous$$aybe post your whole script...
like Jusin said: you need at least 2 colliders in order to trigger anything. I guess the "gameobject" you're talking about is stationary and the child object's spherecollider is marked as "isTrigger". I'm not sure if your player have a CharacterController if it can trigger it. We had similar problems in our game but I have to try your way first. And remember: to get collitions or trigger events one of the colliders need a rigidbody.
Just tried it: when a CharacterController or a "normal" collider with rigidbody enters the trigger the animation of the stationary object get played. But if i move a simple collider without rigidbody into my trigger, nothing happens like the documentation says.
Oh, and sorry Justin for misspelling your name (forget the "t") ;)
yes, I just tried it with a rigid body too and it worked! so how can I get it to work with like a box collider ins$$anonymous$$d?
Answer by The_r0nin · Jan 14, 2011 at 11:30 PM
The parent of a transform is itself a transform, so you are trying to trigger the transform's animation, not the GameObject's animation. Try:
transform.parent.gameObject.animation.Play ("MyAnimation");
thanks I've been trying to test this so I put in a Debug.Log to see if it would print something and it didn't so I think the other reason it's not playing is that the trigger doesn't notice that it has something enter it. any advice on that?
no, that's not the problem, all components have crossrefs to other components like transform, audio and animation. That's absolute legit.