meCreating A Ledge Grab in Unity — Part 4: Change Player GameObject Position After Animation

Moving the player to the final position after the climb animation.

Rusben Guzman
3 min readMar 24, 2022

First I added a climb animation in the player animation controller.

The climb animation we are using for the player controls the 3d model, so when the animation finishes the 3d model is in a different position than the player. The solution is to move the player game object to the same position where the animation finished.

In the platform we are going to create a new empty game object with the final position.

In the Ledge Script you have to create a variable to get the reference to the stand position and a method to get the value of this position.

In the player script I declared a new variable to save the stand position for the player and a flag called onLedge to check when the player is on the ledge. If the player is onLedge I check for the E key to start the climb animation. Then create a new method called GrabLedgeComplete to change the position of the player and enable the controller.

Now in the ledge grab checker script in the OnTriggerEnter function we check for the player tag and set the stand position.

Then in the animator controller we have to create a transition from the hanging animation to the climb animation. Next create a new behavior script.

In the new script we have to use the OnStateExit script we can access to the player controller script through the animation component and call the GrabLedgeComplete function.

To make a smooth transition from climb to idle animation we have to set the transition duration to 0.

And that’s it we have a complete climb animation and the player in the correct position.

--

--

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.