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

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store