Day 141 — Setting up a Reload Animation

Connor Fullarton
3 min readAug 3, 2021

--

Hey and welcome!

Last one here for this project and it’s going to be a short one that covers the implementation of a reload animation.

Start off by making sure that you have your animation window open which you can find under Window > Animation and then click on your gun in the hierarchy and choose the create option in your animation window and call this Reload. This will automatically create a new animator for you which you can go to and add in a new trigger parameter called Reload. Once you’ve done that, create a new state in here called Idle and make this the default state by right-clicking it and then add a transition from this to your Reload state and vice versa.

Ideally you’ll want an actual idle animation in the idle state but this can work for what we have planned here. Make sure as well that the transition heading to your reload doesn’t have an exit time and that the other one coming back does have exit time.

Now head back to the animation window and click on the add property option on the left. This shows us a list of all the child objects and properties of our gun that we can access, in this case we want to add the Transform Rotation and Transform Position properties here.

In order for us to get a feel for the animation we’ll need to put it together while the game is running so run the game and click off it when you have a level position and then stretch out your end keyframe in your reload animation to the 2 second mark and hit the record button.

You’re now free to rotate and move your gun about, you should put in a keyframe around the halfway point of the animation where the gun is lifted a bit tilted to the side, luckily our hands are following along with the animation too thanks to the work we’ve done!

Next up is the tricky bit and is mostly going to be down to your own eye and judgement here but basically when your gun is tilting or about to tilt you’ll want to move your Hand_Position_L out of the scene view along with the clip object in your gun (Can create a cube object to prototype this!). Then while it’s fully tilted or about to tilt back to its original position you bring the clip back up with your hand grasping it at the bottom so that you have something like this or better:

Bit of a rush job but with a bit of tweaking you can get something really nice looking! Lastly go ahead and create a Gun script and add in this bit of code to it:

private Animator _anim;void Start()
{
_anim = GetComponent<Animator>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
_anim.SetTrigger("Reload");
}
}

That’s all it takes, pretty easy to implement and there’s a lot of room for improvement too!

--

--

Connor Fullarton

Hey and welcome! My name is Connor and my goal here is to put out a daily post for a full year about my game development journey.