2.5D Cert Req: Player Animations

Gabriel Perez
4 min readDec 29, 2021

--

Setting up animations is a fun process to make your character come to life!

I’ve dealt with animating characters through unity before, but… only for 2D games! I had an idea that for a 3D-based project, it had its complexity right in the front door. A 3D character model alone has its intricacy’s that I am curious about, and it leaves me with an overwhelming feeling… in a good way.

After having a basic movement system for my player, with the use of a capsule, I went ahead to download a character model from FileBase to turn things around.

Future soldier for the win! With the environment looking sci-fi-ish, I figured a character looking futuristic would fit well.

I went to Mixamo to download some animations. One for idling, running, idle jumping, and a run jump.

There are many cool animations that you can think of in there. I saw the animation up top that I would like to use when my player falls off the platform to his death. But I am not sure if that will be today! Maybe tomorrow.

I created a new script to handle the animation for the player. I called it “PlayerAnimation.” It holds a reference to the animator which has the animator controller for all my animations. I also have a reference to the player. The player reference will pass the velocity to a new variable to set up the animation.

public class PlayerAnimation : MonoBehaviour
{
private Animator _animator;
private Player _player;
private void Awake()
{
_animator = GetComponentInChildren<Animator>();
if (_animator == null)
print(“Animator is null”);
_player = GetComponent<Player>();
if (_player == null)
print(“Player is null”);
}
private void Update()
{
Vector3 _velocity = _player.GetVelocity();
_animator.SetFloat(“speed”, Mathf.Abs(_velocity.z)); bool isJumping = _player.IsJumping();
_animator.SetBool(“isJumping”, isJumping);
}
}

I might as well show the script. I like to use the Single Responsibility Principle. Have a script do one thing only!

I started with the idle animation. I download one that I liked and went ahead to pass it into my asset folder.

I had to do some magician stuff to get it working. Make sure you choose “Humanoid” for the animation type!

Also if your animations are animated for player input movement, then you might want to consider messing with these options.

For idling, I want to loop the animations 24/7. By baking the root transform, you are telling Unity that you want your animations to stay with the player transform at all times. Or else you’ll move, and the animation will move away from your current position.

I went ahead to download the rest of the animations needed for my player. Hooking them up in the Animation window looks complicated, but once you get the hang of it, it’s simple. Setting up conditions for each state is where the animation window shines. Once I have my parameters set, I can set them as conditions for the communication between each state. Then I can have access to these parameters in the “PlayerAnimation” script I created earlier to handle the animation from code.

In conclusion, the process of setting up animations for your player is an awesome feeling! It makes your character come to life. There are more features to learn from in the Animation and Animator window alone that I can’t fathom yet! There’ll be a time when I must explore such depths… that time will come! :)

Gabriel

--

--

Gabriel Perez
Gabriel Perez

Written by Gabriel Perez

Hello everyone, My name is Gabriel Perez, I am a Unity Developer and a creator who is always learning and experimenting.

No responses yet