- Home /
Is there a way to make keyframes of an animation conditional?
Basically, I have two different types of sword sprite: some that are vertical, some that are at a 45 degree angle. I have animated a holder GameObject called "Weapon" at 0 degrees, but I would like to be able to edit the animation so it is at 45 degrees if the sprite is one of the ones that is naturally at 45 degrees.
Pseudocode:
if (isVertical)
{
keyframe.rotation = 0;
}
else
{
keyframe.rotation = 45;
}
I just really don't want to have to make a bunch of new animation states and blend trees for a type of weapon that is just tilted a little bit. If there's a way to do this, let me know, but I am also open to other simple solutions. Thank you!
(I tried just rotating the tilted sprites by 45 degrees in GIMP, but they turned out very blurry).
Answer by jackmw94 · Jun 12, 2021 at 06:32 PM
I'd recommend having your sword sprites as a child of your animated weapon object, then you can have the same animation on the root object and your child objects can be rotated without having to mess with the animation clips.
There's no easy / built in way of having conditional keyframes. If you're set on that idea you could create the animation clips at runtime and use an animator override controller to set them back to your animator but this sounds like a great deal more trouble.
Yeah I don't know why I never thought of doing that, even if it means re-animating a new object that just sounds like the more logical and easier thing to do. Thanks so much!