Tutorial #2


This tutorial started off much better than last week. Unity actually was working, and I came into the class with all my assets ready to go. Exporting from blender was super painless - from previous experience I don’t trust importing .blend files so I had the foresight to export my fully rigged character, with animations, as a .fbx file. All of the animations imported correctly and without a hitch, which is probably a world first.

After importing the animations, making the character controller as well as movement and waving scripts, it was all ready to go!

I had some issues with the events for some reason they just weren’t triggering. I later resolved this by… just doing it again. No clue what wasn’t working, I think I was just lazy and/or tired that morning. It works now. No questions.

Back to what I was doing in class. The walking animation script! I made a new script that gets the animator and character controller components from the player, then during the update cycle it takes the current horizontal velocity and updates the animation accordingly. I also added in some variables for the animations playing speed, as well as the damping value to apply between the resting and walking animations. To hook this up to the animator, I simply made a new float condition to transition between walking and resting.

Animator animator;
CharacterController cc;
public float damp = 0.1f;
public float animSpeed = 1f;

...

Vector3 horizontalVelocity = new Vector3(cc.velocity.x, 0, cc.velocity.z);
float overallSpeed = horizontalVelocity.magnitude;

animator.SetFloat("Walk", overallSpeed, damp, Time.deltaTime);
if (overallSpeed > 0.1f) {
     animator.speed = overallSpeed * animSpeed;
} else {
     animator.speed = 1;
}

This worked an absolute treat! During testing I set the animation speed to be way too fast which resulted in some rather funny looking animation. I would add it to this devlog but the gif I took is way over itch.io’s maximum upload size, and is nearly impossible to compress further with ezgif so just take my word for it.

Great success!

Get utas kit207 portfolio

Leave a comment

Log in with itch.io to leave a comment.