0
votes

I'm trying to animate a hierarchy of 2D sprites (essentially body parts) by explicitly setting sprite positions at various key frames throughout a given animation clip. Unfortunately, Unity is implicitly changing all of the sprite positions using interpolation between key frames. This causes the sprites to look like they're sliding around rather than immediately transitioning into their correct positions.

So far I've come up with 2 rather poor solutions:

  1. I could potentially create separate animation clips for each combination of sprite positions and transition between them using mecanim parameters or in code, but this seems tedious at best and inefficient at worst.
  2. I could add more keyframes (either in the animator tab or in the curves screen) that maintain each sprite position until just before they need to be updated. This is a slightly better option but also extremely tedious.

Is there any way to tell Unity to disable animation interpolation at least as far as positions are concerned? Thanks.

3
Have you tried right clicking on the keyframe and changing properties there?Hristo
@Hristo, yes, I read that selecting the "flat" option there might cause the clip to forego interpolation, but this does not seem to work, even when this option is chosen for all the key frames.Mir
Well the only other thing I can think of is adding another keyframe right before you want your transition. The keyframe needs to be the same as the previous one, hence no interpolation (visible at least).Hristo
Was hoping to avoid this (see #2), but you're probably right.Mir
O yeah missed that one, but I think in general the animations are meant to be interpolated. Unless you manage to change that curve in a way (could be code involved). Good luck!Hristo

3 Answers

1
votes

Have you checked Brackeys video of animating 2D in Unity? Maybe it can help you :)

The following link is his video on how to animate 2D sprites. https://www.youtube.com/watch?v=whzomFgjT50

1
votes

In the current version of Unity (2019.3), go to curves view, right click a keyframe node and select Left Tangent -> Constant. You may want to use Right Tangent depending on the use case. That should give you the instant change you're looking for.

0
votes

Alright, I've come to the unfortunate conclusion that Unity forces you to use curves when dealing with animation keyframes and that you need to add an extra set of keyframes for abrupt shifts in animation.