GameDevHQ Crash Course #30 Contextual animation events

Jason Dixon
3 min readApr 14, 2021

--

Having animation events for different contextual events can elevate a game. So this time we are going to add contextual ledge grabbing.

For this we are going to need a few things, first we need to add a bounding box for where we want to the grab area to be, and we need to add a box above the player roughly where our hands are going to be so we can ‘grab’ the ledge when they collide.

Make sure this is childed to the player gameobject, as we want this to move with the player.

Add a 2d box collider to both of these so we can have them interact. Then to the box added above the player character, we add a script that will be checking for collisions for the ledge. If it finds a ledge we want to transition to the hanging animation and we also want to cancel all movement on the player script, for this I turn off the character controller, till we finish climbing or drop from the hanging position.

Next we are going to want to climb up or drop, dropping is simple of re engaging the character controller and ignoring the ledge collision for a short period of time. Climbing is a little bit more involved as we have an animation we want to play and then move to the ending position of this animation.

So first we want activate your climbing animation.

Adding an extra event from our hanging idle animation as that is the only state we will be climbing from. We also add a state from the climbing to idle with no condition as we want to be moving to the idle animation when the climbing is finished.

Now before you go to much further. Check the movement displacement of the climbing animation, as we want to add that to the players position at the end of the climbing animation to set the players position. For example, the climbing animation I am using goes up 5 units and forward 0.9 units. so using a vector 3 we add (0,5,0.9f) to our position when the climbing animation ends and the idle animation begins to translate our animation movement to actual movement.

Now you have made your first contextual animation event.

--

--