Tutorial 2 - Animation in Unity


Today it was time to take the exciting step of bringing my humanoid character into Unity, animations and all Initially I had some trouble getting the animations to come in using the .blend file... it never seemed to show the animations but nothing a quick export as an .FBX file didn't fix.

Next step was to link up all the animations using the Animator. I setup three anaimation states, one for an idle pose (when the character is still), a wave and a walking state.

I then added a door that would be triggered tro open (well maybe dissapear is a more accurate word lol) when the player enters a given 'trigger zone' near the front of the door.


Then I added a C# script to check if the object inside the 'trigger zone' was the player, and if so trigger a given action. In this case disabling the door game object.

I then started work on getting my walk animation correctly linked up to start whenever the player has a speed of greater than 0. I also slowed down the player's max speed to better match the footsteps shown in the animation cycle.

I wrote my own script to connect the Animator and the Character Controller components, keeping the Animator informed of the current player speed. I'm not sure if this was as unnecessary step and there was an easier way to connect  the velocity directly to the animator without requiring this middle-step script.

Below is the code added to the Character Controller to work out the current velocity. This distance based approach is required due to not using a Rigidbody component to handle the movement, which would inherently offer a velocity variable.

lastLocation = currentLocation; // location of character at last frame
currentLocation = transform.position; // location of character at current frame
velocity = (currentLocation - lastLocation).magnitude; // velocity of character as difference between two locations

The final walking animation is shown below.


Leave a comment

Log in with itch.io to leave a comment.