- Home /
How do I trigger my animation with a box (collider) attached to a road ramp?
Please I need help in making a collision script work. I have several animations for my deer(trotting, jumping, walking, died, etc.). But I want the "deer trotting" to be activated when my car passes through a box collider I attached to road ramp. After this I want, I want to set a condition in the script which is - if the car collides with the deer, the "deer died" animation should play. Here is the script I wrote but it seems not to work, no collision detected and the deer is stagnant. I also made a new trigger animation controller with transitions but I'm still not able to get it work. Pls offer me your kind assistance .alt text

,
Hey instead of triggers in animation try using bools and transitions like this here (link to documentaion) Make the transitions occur at the moment of value becoming true/false by setting the transitions duration to zero .
Hope this helps.
I'm guessing you forgot to attach the link but thanks for your response. The experiment I'm conducting will be using a driving simulator (with steering wheels and pedals) which may not have any key for me to setBool.
Answer by JustAbhi · 2 days ago
Sorry about that i hyperlinked the text but i guess it didn't work.
So what you need to do is have a parameter in the Animator(See this here) and set the transitions to make the proper animation play on value change.
 using UnityEngine;
 using System.Collections;
 
 public class SimplePlayer : MonoBehaviour {
     
     Animator animator;
     
     // Use this for initialization
     void Start () {
         animator = GetComponent<Animator>();
     }
     
     // Update is called once per frame
     void Update () {
         float h = Input.GetAxis("Horizontal");
         float v = Input.GetAxis("Vertical");
         bool fire = Input.GetButtonDown("Fire1");
 
         animator.SetFloat("Forward",v); /*see that this String will have the same name as the one in the parameter you make in the Animator component's  parameter list */
         animator.SetFloat("Strafe",h);
         animator.SetBool("Fire", fire);
     }
 
     void OnCollisionEnter(Collision col) {
         if (col.gameObject.CompareTag("Enemy"))
         {
             animator.SetTrigger("Die");
         }
     }
 }
Hope this helps.
This is the hyperlink : https://docs.unity3d.com/Manual/AnimationParameters.html
Your answer
 
 
             Follow this Question
Related Questions
spawning a prefab that have animation 1 Answer
Run animation when countdown reaches 0 2 Answers
How make animation on Unity 3D from XML file? 0 Answers
Multiple Cars not working 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                