Xanimator V.3.1.0 | Smooth/Nonlinear animation transitions (Discontinued)

Xanimator

"Why does roblox only give us like linear fades with the :Play() function?" - Frayxen

What is Xanimator?

Xanimator is a component that allows you to tween the animation weight of AnimationTracks, this can be used to transition between 2 animations smoothly, allowing you to create more human looking transitions.

Xanimator works by Queueing up the transitions and then stepping them using math.lerp() and TweenService:GetValue().

Here is a video for demonstration:

(Music made by Kuko)

There is more to come but as of now this is all it does.

Why I made this

Over the years while developing projects within the Roblox engine I always struggled working with animations due to the fact they are extremely limited, but mainly the transition part, it’s always linear and this absolutely ruined combat feel for my games and animating every transition by hand is simply inefficient.

Inspired by this post:
Nonlinear transitions between animations - Feature Requests / Engine Features - Developer Forum | Roblox

I had an idea, and after building a prototype proving it was possible I was able to create Xanimator.

How to use

Install the module and drag it into your place of choice, then require it.
local Xanimator = require(path)

Start by creating a new Xanimator component for your existing rig by passing it’s Animator.

local Rig = path
local animator = Xanimator.new(Rig.AnimationController.Animator)

Now load your animations

local Animations = path
local Idle = animator:Load("Idle", Animations.Idle)
local Walk = animator:Load("Walk", Animations.Walk)

Let’s set up the update cycle.

local RunService = game:GetService("RunService")

RunService.PreAnimation:Connect(function(deltaTime: number)
    animator:Update(deltaTime)
end)

Awesome now let’s play them and transition between them

-- Start weight at 1
Idle:SetWeight(1)
Idle:Play()
-- Start weight at 0
Walk:SetWeight(0)
Walk:Play()
-- Transition between them
Walk:Blend(1, 1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
Idle:Blend(0, 1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)

If you would like to see it in action there is an example place provided:

Methods

There are 2 components.

Xanimator

:Load(name: string, animation: Animation)

Loads animation.
Returns Anim component.

:Remove(name: string)

Removes and destroys animation.

:Update(deltaTime: number)

Updates component, use RunService.PreAnimation to step.

:Destroy()

Destroys Xanimator component.

Anim

:Blend(targetWeight: number, duration: number, style: Enum.EasingStyle, direction: Enum.EasingDirection)

:SetSpeed(speed: number)

:SetWeight(weight: number)

:Play(fadeOutTime: number, fadeOutStyle: Enum.EasingStyle, fadeOutDirection)

:Pause()

:Resume()

:Reverse()

:Stop(fadeOutTime: number, fadeOutStyle: Enum.EasingStyle, fadeOutDirection, speed : number)

Things to note

  • Easing styles such as back and elastic do not work since they overshoot. AdjustWeight() only works on values from [1, 0].
  • This resource still has more features to come such as animatin groups to save and manage animation priorities efficiently.
  • There might still be some bugs and memory leaks, if you find them report them to me and I will try and fix them as soon as possible.

What did you think

  • I will be using this!
  • I like this.
  • It just needs some improvements.
0 voters

Credits

Signal+|Insanely optimized script signal - Resources / Community Resources - Developer Forum | Roblox

Download

Xanimator V3.1.0.rbxm (7.5 KB)

Previous versions

Xanimator V3.0.0.rbxm (8.1 KB)
Xanimator V.2.1.rbxm (6.9 KB)
Xanimator V2.2.0.rbxm (6.8 KB)
Xanimator V2.1.0.rbxm (6.6 KB)
Xanimator V2.0.0.rbxm (8.3 KB)
SmoothAnimator V1.0.0.rbxm (8.4 KB)

48 Likes

Update V2.0.0

Xanimator has updated, here’s what’s new:

Changelog

  • Reworked the entire resource to be more intuitive and developer friendly by changing animations to be components with their own methods you can call similar to animation tracks.
  • Implemented more methods: :Pause(), :Reverse(), :SetWeight(), :SetSpeed(), etc.
  • Bug fixes.

Update V2.1.0

A minor update, that’s it.

Changelog

3 Likes

Im try it soon. Do its a custom animator class or simple wrapper?

1 Like

It is a wrapper to some extent; this was done because using the default Roblox functions will trigger linear transitions, that’s also why the Finished event exists too.

Although for the things that aren’t wrapped you can directly modify the animation track, I know it is a bit clunky but it was left like that to save memory.

Also roblox gives you no way to get all loaded animations inside an animator, so this fixes that by storing them in a dictionary so you can check them all.

1 Like

If I understand correctly, this is basically a custom TweenService, that works with animation blending?

Also I recommend using GitHub instead of manually keeping track of previous versions. That also allows people to easily and quickly view the source code.

1 Like

It is a component mounted into an existing Animator instance.

It allows you to load animations and then manipulate their weight using easing styles, Roblox’s :Play() function only supports linear fades where the weight linearly transitions to the target weight.

Although it is supposed to lessen the pain of having to manage animations but those features are not implemented yet.

I don’t really like using github as of now, I will probably end up using it later since in college they make us use it.

1 Like

Update V2.2.0

Changelog

  • Added :Between() method to Xanimator class.
  • Added :Between() method to Anim class.

These new methods should make transition from A animation to B animation less of a pain, I plan to add some ways to manage and cancel blends in future updates too as currently the only way to do so is really clunky.

Update V2.2.1

Changelog

  • Fixed an issue causing a Blend’s BlendData[BlendData.Duration] to turn nil when overwriting a blend.
  • Fixed a memory leak when overwriting a blend.

Please update to this version otherwise the resource is quite literally unusable when cancelling your transitions.

I love you bro thx for thisss.

1 Like

Update V3.0.0 [EXPERIMENTAL]

It’s been a long time, sorry for that, the reason updates are slow is because this is the animation engine my game uses, and since my project has been still in its pre-production phase this means I haven’t had the need to update it.

I would also like to state this version is experimental and prone to some bugs since I haven’t had time to fully test it, I’m publishing it in hope maybe some of you guys can help me find some bugs, either way I will be cleaning up the code a bit more later and fix some of them myself.

This version aims to make it easier to use so you don’t have to waste time calling a bunch of methods just to play your animation, I also ditched the “Memory optimization” thing because it just made it harder to develop and debug, later on once everything is finished I will optimize it.

Changelog

  • Rewrote the entire thing from the ground up.
  • There is no need to play the animation and then set the weight, :SetWeight() now works around this by saving the weight while the animation is stopped and applying it once it is played.
  • Added safety checks to prevent fade transitions from breaking if a developer starts a blend mid-way or tries to Resume the animation, replay the animation at the exact position it was paused at to cancel this.
  • When calling :Stop() once the animation’s fade out completes the animation track is actually stopped now.
  • Added more events to give developers more to work with, not all of them are enabled yet.

I would like to reiterate this version is still experimental and I will be polishing it over time.

2 Likes

Update V3.1.0

Sorry for last release, I took the entire day to patch all the bugs I could find, I originally thought it only might have had a few bugs but turns out it wouldn’t even run sometimes, my bad…

Changelog

  • Mayor bug fixes.
  • Reduced memory usage by bringing back the array with enums to store BlendData.
  • Minor changes in the way the methods behave.
  • Removed methods such as :Reverse(), :Pause() and :Resume() and associated events, because I think these are just bloat.
  • Changed the stepping method to not rely on delta Time as floating point errors could accumulate based my hypothesis.
4 Likes

Hey, cool module!

Unfortunately, for me, the example place just refuses to load. I dont know if this is an issue on my end or a problem with the game. Just reporting this and thought you should know!

Keep up the good work.

1 Like

The example place is published with CharacterAutoload disabled, this is to prevent random exploiters from joining and using termination exploits like the one where one joins in playing innapropiate animations using CFrames and the other one reports the place so a moderator reviews what is happening in the moment.

To view the little demo download it and use the Run option, you can see there’s a rig that will start moving, although I don’t recommend using the example place as it is outdated.

1 Like

Due to the recent situation that has been going on with Roblox I have decided to no longer develop for this platform and therefore this resource will no longer be supported.

1 Like

valid reason I wouldn’t want to be associated with this disgraceful platform no more

2 Likes

Godot doesn’t support bad actors unlike Roblox.

3 Likes