Snap CharacterController Position to Last Animation Position

I'm trying to get a "climb ledge" animation to work with my character controller. Right now, my climb ledge animation will play out but when I go to sync up the players new position with the ending position of the animation the rotation of my mesh is buggered:

http://grab.by/9YLT

If I move using WSAD after that then the rotation seems corrected:

http://grab.by/9YLV

The code starts with the player being near to a climbable surface:

RaycastHit hit; if( Physics.Raycast( transform.position, transform.forward, out hit, 1.0f ) ) { if( hit.transform.gameObject.tag == "Climbable" ) { animation.CrossFade( "ClimbUpOnLedge" ); } }

The animation plays, and I have an Animation Event which calls the following method after the animation is done playing:

public void ClimbUpOnLedgeCompleted( )
{
    transform.position = pivot.transform.position;
    animation.CrossFade( "MeleeIdle" );
}

Seems pretty basic to me - but i'm missing something here, can anyone help?

1 Answer

1

Ended up moving to a non-kinematic capsule collider and freezing rotation, which does not truly work either, however using this did the trick:

    rigidbody.MoveRotation( Quaternion.Slerp( transform.rotation, Quaternion.LookRotation( new Vector3( lookAt.x, 0, lookAt.z ) - new Vector3( transform.position.x, 0, transform.position.z ) ), Time.deltaTime * rotationSpeed ) );

essentially 0'ing out the y rotation entirely.