Have you ever wanted to create your own custom animations to play on the player, but then saw the default Animate script provided by Roblox and was too confused to even begin? Well, worry not! For I have created a new Animate script package which is both quite small and very easy to use.
The package is divided into 3 modules: the Controller module, the Action module and the Core module (which has a CoreAnims module inside it to store all the animation information.)
The Controller module is just there as a central… well… controller for both the Action and Core modules.
The Core module is the one that handles all of the core animations, such as walking, jumping, falling. swimming, etc. Core animations are not overriden by the Action animations made using the Action module. Instead they play alongside eachother
The Action module is the one that handles action animations, such as tool slashing, drinking a beverage, etc.
METHODS
Action Methods
-
Action:DefaultInfo(AnimId: string): Action.Info
Returns a pre-filled Info table which can be used with Action:PlayAction(…).
-
Action:PlayAction(ActionName: string, Info: Action.Info): ()
This method of the Action module allows you to play an Action priority animation with a certain name.
CODE SAMPLE:local Animate = require(AnimateModulePath) --pseudocode local MyActionId = "rbxassetid://1234" Animate.Action:PlayAction("MyAction", Animate.Action:DefaultInfo(MyActionId) -- Plays MyAction as an action animation, ontop of the Core animations.
-
Action:StopAction(ActionName: string): ()
Stops and removes a created Action animation using it’s name.
CODE SAMPLE:local Animate = require(AnimateModulePath) --pseudocode Animate.Action:StopAction("MyAction") -- Stops and removes MyAction.
-
Action:StopAllActions(): ()
Does what :StopAction(…) does but instead of only stopping 1 Action of a specific name, it stops and removes all currently running Actions.
Core Methods
-
Core:DefaultInfo(AnimId: string, Perpetual: boolean, EndAfter: number): Core.Info
Returns a pre-filled Info tablr which can be used with Core:InterruptCore(…)
-
Core:InterruptCore(Info: Core.Info): ()
When Info is not nil, all Core animation processing is stopped and instead is replaced by an animation provided by Info. If Info.Perpetual is false then usual Core animations will resume after Info.EndAfter.
Else then Core will not resume until after Core:Resume() is called.
CODE SAMPLE:local Animate = require(AnimateModulePath) --pseudocode local MyCustomAnim = "rbxassetid://1234" Animate.Core:InterruptCore(Animate.Core:DefaultInfo(MyCustomAnim, false, 5)) -- Perpetual = false, EndAfter = 5 -- After 5 seconds, all usual Core animation processing will resume.
-
Core:Resume(): ()
When this is called, if Core:InterruptCore(…) has been called before then it will stop any current interruptors and resume regular Core animations.
CODE SAMPLE:local Animate = require(AnimateModulePath) --pseudocode Animate.Core:InterruptCore() -- Called with no arguments, so Core will not resume until after Core:Resume() is called. task.wait(5) Animate.Core:Resume() -- Resumes regular Core animations after 5 seconds
EVENTS
Action Events
-
Action.ActionPlayed; Args = (ActionName: string, AnimTrack: AnimationTrack)
Fires whenever a new Action is played using Action:PlayAction(…).
-
Action.ActionStopped; Args = (ActionName: string)
Fires whenever an Action is stopped using Action:StopAction(…)
Core Events
-
Core.NewStateCreated; Args = (NewState: string, AnimTrack: AnimationTrack)
Fires whenever a new State (such as Idle, Running, Walk, etc.) is created.
CODE SAMPLE:local Animate = require(AnimateModulePath) --pseudocode local MarkerConnection Animate.Core.NewStateCreated:Connect(function(NewState, AnimTrack) MarkerConnection = AnimTrack:GetMarkerReachedSignal("ExampleEvent"):Connect(function() print("Event Reached!") end) end)
-
Core.OldStateOverwrite; Args = ()
Fires whenever an old State is overwritten by a new one.
CODE SAMPLE:local Animate = require(AnimateModulePath) --pseudocode local MarkerConnection Animate.Core.NewStateCreated:Connect(function(NewState, AnimTrack) MarkerConnection = AnimTrack:GetMarkerReachedSignal("ExampleEvent"):Connect(function() print("Event Reached!") end) end) Animate.Core.OldStateOverwrite:Connect(function() if not MarkerConnection then return end MarkerConnection:Disconnect() end)
Enjoy! (please report any bugs here ty)
Also, worth to mention that weight is kinda useless right now, if you want to implement weight-based core animation playing feel free to implement that yourself