- Home /
Trouble getting a trigger to activate an animation
Hi, im having trouble getting a trigger i have to play an animation on a chest to open the lid. I have a mesh collider on the "Chest1" and have istrigger ticked and have an animation on it aswell with "Take 001" in the animation slot. Ive also got a rigid body on my "Player" which is the first person controller incase thats the reason it wouldnt play. i want it so that once the "Player" reaches the "Chest1" it would start the animation "Take 001".
I have no idea on scripting made the script im using from some previous guidance. Would appreciate any help in correcting this.
Thanks in advance
function OnTriggerEnter (Player : Collider) {
animation.Play("Take 001");
}
Well, in the function, I'd put in print("Test"); and see if that prints to see if the actual trigger is actually getting triggered...
ok, sorry im totally new to this, its for a university project. But what does that actually mean? how would the code change, as in where do i type print("Test") and wat would i be expecting to see from a success or failure?
Answer by matchstickct · Aug 06, 2013 at 05:42 PM
Took me most of today to figure this one out. When you are importing basic (non-rigged) animations from max, you need to make sure they are checked as 'legacy' on the importer in unity (you can find this under the 'rig' tab in the importer).
When I did this your script worked.
Answer by Justin Warner · Apr 14, 2011 at 03:29 AM
function OnTriggerEnter (Player : Collider) {
print("test");
animation.Play("Take 001");
}
This'll print something in the Log.
Comment back and I'll help as much as I can, but off to bed for me, I'll reply in ~8-9 hours.
But tell me if this does or doesn't print Test when you enter the trigger.
Thanks!
thanks for the help so far. I used the code u suggested, when i moved over the chest which is the trigger it came up with a little speech bubble with an exclamation mark in and said test next to it. When i clicked it this opened up,
test UnityEngine.$$anonymous$$onoBehaviour:print(Object) NewBehaviourScript:OnTriggerEnter(Collider) (at Assets/NewBehaviourScript.js:2)
then if i click that it opens up the edit script page. Does this mean the trigger works? if so can you think of a reason why it wont play the animation then.
Thanks
Alright, this means that YES, the trigger is being... tripped? Haha. But anyways, if I was to guess, your animation is not named right. Also, is the animation on the object that is hitting the trigger? Or on the object with the trigger?
ok haha so atleast ive done that bit right. ok the animation is on the chest which is the trigger. Ill look at rena$$anonymous$$g it then see if that helps.
Is the script also on the chess than? I'd assume it is... Or is it on the player?
the mesh collider on the chest is acting as the trigger, and ive gt the animation attached to the chest aswell. Should i have something else so that my object isnt the trigger? i saw that is an activate trigger script in standard assets bt i dotn no how to apply that. As i said my script myt nt be right for what i am after doing, if you have a suggestion of some code that would be, im happy to use that, The name of object with the animation on is "Chest1" the name of the animation is "Take 001" and ive named my first person controller "Player" who i want to activate the trigger.