Abrupt change of position between animation transition

I’m making a ledge grab mechanic and it’s working. But as you can see in this video, there’s a strange behaviour happening in the transition from ledge climbing to idle, as the sprite goes towards up-right for a frame or so.


I’m directly changing the transform.position at the of the animation with an animation event. The frames of the climbing animation have custom pivots and the idle animation got its pivot at the center. Using Tranform.Translate() resulted in the same problem and the RigidBody2D.MovePosition() couldn’t move through the platform collider.


Any idea about how to fix this? I checked this question too, but I couldn’t find what they were talking about. I’ve also tried changing when the animation event occurs and placing an idle frame at its end. Here’s my code that runs as soon as the climbing animation ends:


collidersGroup.gameObject.SetActive(false);
collidersGroup.localPosition = Vector3.zero;

if (facingRight) {
    transform.position = new Vector3(transform.position.x + playerBounds.size.x + ledgeClimbXOffset,
        ledgeBounds.max.y + playerBounds.size.y + playerBounds.size.y / 5 + ledgeClimbYOffset);
} else {
    transform.position = new Vector3(transform.position.x - playerBounds.size.x - ledgeClimbXOffset,
        ledgeBounds.max.y + playerBounds.size.y + playerBounds.size.y / 5 + ledgeClimbYOffset);
}
animator.Play("idle");
collidersGroup.gameObject.SetActive(true);

I would guess that you are moving the gameobject the sprite is a component of. What I would do is make the sprite a child of your player gameobject. Then you can move it around and the animated sprite will move relative to parents position.

It works now, at last. But there were so many modifications that I don’t know exactly what did the trick. I deactivated the loop time in the animation file, put an idle frame at the of the ledge climb animation and put the animation event exactly above it. I’ve also extended the duration of the last ledge climb animation frame, but I’m not sure it was affected by that.