Hello guys! My child is doing school project in Unity and she asked me to help her with this one. She created landscape and imported prefabricated free horse from Unity store (yes, it’s project which includes horse riding, but without human, horse is character). She imported the horse and we solved controlls (forward, backward, lef, right, jump). Horse animation is in fbx format and I can change his default behaviour but don’t know how to change animation when key is pressed. I want to change from idle to “trot” when any of wsad keys are pressed, “run” when holding shift and “jump” when space is pressed.
Can someone help? Is it possible from fbx file to call out different animations regarding pressed key?
Thanks in advance.
Open up the Animator window. This can be found at the top under “Window” and “Animator” (I believe it has no hotkey associated with it.) When this opens, select your Game Object in your Hierarchy. If the Animator has an orange box with the name of your animation in it, this is why it is auto-animating. The way that I fix this is that I right click inside the Animator window and create a new state and I call it Idle. Inside Idle I don’t assign any animations at all. Right click Idle and set it to the default state, which should then make it orange. From here you want to right click on Idle again to create a transition, at this point an arrow will appear underneath your mouse cursor and you will want to use it to click on your other animation state (the one that was originally orange.) This tells the Animator you want to go from Idle (where no animation is playing) to a state where an animation is playing. In the bottom left of your Animator window is a box called “Parameters”, go ahead and click on the + on the right side of that box and add yourself a Trigger which you can name anything you want. Then click on your transition arrow from Idle → Whatever Animation and check the inspector. Change the Condition from “Exit Time” to your Trigger. You will also want to set a transition FROM your Animation TO Idle so that it exits after the animation is complete (and you can use the default settings for a transition for that, no new triggers required.)
After you do that block of text, go into your code and inside the check for input write
GetComponent().SetTrigger( “NameOfYourTriggerYouMade” );
public bool animation_bool;
if(animation_bool == true)
GetComponent<Animation>().SetTrigger( "NameOfYourTriggerYouMade" ); }
animation_bool = true;
For more information visit animation play on key press