- Home /
Animation begins at start of Gameplay before colliding with trigger
I have set up an animation which is supposed to start when colliding with a gameobject. However, this animation occurs at the start of gameplay. The animation is supposed to occur when colliding with gameobject, and stop when exiting the gameobject. The animation starts at beginning of gameplay, then when i collide it continues. Then when I exit the object it stops as it should. However, I do not want it to start at the beginning of gameplay. Below is an image of my Animator.
I have then linked an image of the code which shows that when entering the gameobject, the animation plays. And when exit the animation stops.
You need to have a different animation state to transition from, so that default it's in an "idle" state and when collision occurs, you change a parameter in animator to move to next transition, usually a trigger or bool.
[SerializeField]
Animator m_Animator;
[SerializeField]
string animatorHash = "trigger";
private bool collided;
void OnCollisionEnter(Collision col)
{
if (collided)
return;
if (col.collider.gameObject.layer == layerIAmLookingFor)
{
collided = true;
m_Animator.SetTrigger(animatorHash);
}
}
Answer by Vollmondum · Apr 07, 2019 at 03:46 AM
You need to specify collidable object tag and only play that animatiin if collided with that tag trigger
hey, not sure if I've done it right. The animation still occurs at the beginning of gameplay but will still proceed to then turn on and off if I enter or exit the colliision
You need to setup the Animator to have a default state that's not the one you want to play on triggering. Your animator trigger "Cylinder", how is the transition setup?
So i have set up an idle state then attached my animation to it - and set up a trigger known as 'Cylinder'.
Answer by bekah_mbrown · Apr 07, 2019 at 06:28 PM
Okay now when I play the lights are active at gameplay, then when the first time I collide with the trigger the animation occurs, then when I exit the trigger the lights turn off and the animation stops(which is what I wanted), but then when I collide a second time the lights still turn on but the animation stops. How do I get the animation to repeat?
Your answer
Follow this Question
Related Questions
Trigger not playing Animation 0 Answers
making an arrowgrab animation play when attackdelay = 0. 0 Answers
Animations don't work with humanoid avatars 0 Answers
Animator Button Plus Transition 0 Answers
Display additional animation on top of other animations 0 Answers