Koby Douek
Koby Douek

Reputation: 16673

Unity animation changes position after repositioning or resizing sprite

I created a simple animation that changes the sprite's position x.

It works well, but when I reposition the sprite or resize the sprite using the editor, I see that the animation's position values were not changed, leading to the sprite to jump over to the previous position.

Here's a snapshot of the animation's keyframes, showing that the starting position is 0.

enter image description here

After I move the sprite around the scence, these value remain 0, and when the animation starts, the sprite moves back to position 0,0,0.

Is there any way to set the animation's position values relative? or make it change automatically when I change the sprite's position?

Upvotes: 1

Views: 5139

Answers (1)

Ali Baba
Ali Baba

Reputation: 349

Values assigned in the Animator always override values assigned in the Editor or in the Update or FixedUpdate methods.

The easiest way to solve your problem is probably by making the GameObject a child-object of another new Gameobject. That way the positions are changed relative to that parent-object and you can just change the position of the parent.

Upvotes: 2

Related Questions