- Home /
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);
Answer by MSavioti · Mar 03, 2019 at 06:08 AM
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.
Answer by WarmedxMints · Mar 03, 2019 at 05:14 AM
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.
The animator can't find the Sprite Renderer because it's not on the same object. And I can take the animator away from the father Game Object because the function that is called in the animation event, is in it.
Your answer
Follow this Question
Related Questions
Is it possible to turn off/suppress event calls in an animation at runtime? 2 Answers
SpriteManager 2 1 Answer
How to do you import Spriter animations into Unity? 1 Answer
sprite animation not playings 0 Answers
How to animate a sprite mask? 0 Answers