Skip to content

Commit

Permalink
Fix preserve loop going to a longer animation starting in the middle …
Browse files Browse the repository at this point in the history
…of it
  • Loading branch information
acidbubbles committed Dec 30, 2021
1 parent cb44239 commit 3ae5afe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AtomAnimations/Animations/AtomAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ private void TransitionClips(AtomAnimationClip from, AtomAnimationClip to)
if (!from.loop)
to.clipTime = Mathf.Abs(to.animationLength - (from.animationLength - from.clipTime));
else if (to.preserveLoops)
to.clipTime = from.clipTime;
to.clipTime = (to.animationLength - (from.animationLength - from.clipTime)).Modulo(to.animationLength);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/AtomAnimations/Utils/FloatExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,10 @@ public static float RoundToNearest(this float value, float modulo)
var half = modulo / 2;
return value + half - (value + half) % modulo;
}

public static float Modulo(this float value, float mod)
{
return (value % mod + mod) % mod;
}
}
}

0 comments on commit 3ae5afe

Please sign in to comment.