- Home /
Can a Trigger be triggered by an animated object (script)?
I have two objects, one is animated by keyframes, the second is a stationary object in the path of the first. Ultimately, I would like to affect the animation speed (or other parameters) of the first object when it enters the second object.
I set the second object as Is Trigger and attached the following script to object one:
function OnTriggerEnter(collision : Collider)
{
if(collision.gameObject.tag == "cube_col")
{
print("trigger collision");
}
}
The animation is run in the Update function of the script (also tried just running it automatically).
The second object has a tag of "cube_col", I also tried using the name of the object too, but this didn't work either.
What am I doing wrong? Is what I'm trying to do even possible?
thanks.
Answer by TonyLi · Apr 04, 2013 at 01:34 PM
It's entirely possible.
Both objects need Physics colliders (http://docs.unity3d.com/Documentation/Manual/Physics.html)
In Edit > Project Settings > Physics, the layer(s) need to be checkmarked to allow collisions (http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html)
As you already did, the second object's collider should be checkmarked Is Trigger.
The type of animation (or lack thereof) doesn't affect collisions. The Physics system only concerns itself with colliders (e.g., box collider, character capsule, etc).
Thankyou, that did the trick, added a rigid body to the first object and all worked fine (after adjusting the layering). thanks again.