AnimationController - Simple animation class

AnimationController

I made this basic controller for fun it creates animations without directly accessing or creating an animationInstance just pure scripting I also added some functions like setLoop(boolean) or AnimationController:Play(animationId)
note: the post :point_down: is created by AI


How to Use:

  1. First, require the module:
local AnimationController = require(script.AnimationController)
  1. Play an Animation:
    Use the :Play() function to play an animation by providing the animationId. You can optionally specify a character model.
-- Play animation on a character
--[[ 
if you want the animation to play on localPlayer's character 
there's no need for characterModel paramenter
]]

AnimationController:Play(animationId, characterModel)  -- characterModel is optional

After the animation finishs itโ€™ll cleanup and destroy itself


Advanced Usage:

For more control, you can create an AnimationController object.

-- Create a new AnimationController with an animationId
local Animation = AnimationController.new(5125161262, characterModel)  -- Pass characterModel or leave it nil for localplayer character

-- Play the animation
Animation:Play()

-- Set it to loop
Animation:setLoop(true)


Using _animation (Internal Animation Object):

If you want to interact with the internal animation object directly, you can access it through Animation._animation.

-- Access the internal animation object
local internalAnimation = Animation._animation

-- Example: print out some properties of the internal animation
print("Animation Length: ", internalAnimation.Length)

Listening for Events:

You can also listen for events such as when the animation ends, loops, or reaches a keyframe.

-- Event when the animation ends
Animation.Ended:Connect(function()
    print("The animation has finished!")
end)

-- Event when the animation loops
Animation.DidLoop:Connect(function()
    print("The animation looped!")
end)

-- Event when a keyframe is reached
Animation.keyFrameReached:Connect(function(keyframe)
    print("Keyframe reached:", keyframe)
end)

Destroying the Animation:

When youโ€™re done with the animation, destroy the animation object to clean up.

-- Destroy the animation object
Animation:Destroy()

Full Example:

Hereโ€™s a full example that plays an animation, adjusts its speed, loops, and listens for events:

local AnimationController = require(script.AnimationController)

-- Create an animation object
local Animation = AnimationController.new(5125161262, game.Workspace:WaitForChild("YourCharacter"))

-- Play the animation
Animation:Play()
-- adjusts speed
Animation._animation:AdjustSpeed(0.25)
-- Set it to loop
Animation:setLoop(true)

-- Listen for the "Ended" event
Animation.Ended:Connect(function()
    print("Animation finished!")
end)

-- Stop and destroy after 10 seconds
task.wait(10)
Animation:Stop()
Animation:Destroy()

Features:

  • :Play(animationId) โ€“ Plays the animation immediately and destroys it after it finishs.
  • :setLoop(true/false) โ€“ Makes the animation loop if true, or stop looping if false.
  • Animation._animation โ€“ Access the internal animation object for more details or custom interactions.
  • No need for AnimationInstance โ€“ Everything is handled with scripting, making it easier to use.

Link to the module:
You can get the AnimationController module here.


5 Likes