Skip to main content

NPCAnimator

Plays and blends animations on an NPC rig by name.

local animator = VluxyAI.Animator.new(model, {
	Idle = { Id = 123, Weighted = true },
	Walk = { Id = 456, Weighted = true },
	Swing = { Id = 789, Weighted = false },
}):Load()

animator:SetWeight("Walk", 1)
animator:Play("Swing")

Load every animation up front in Load; adding tracks later is not supported.

Types​

AnimationInfo​

interface AnimationInfo {
Id: number--

The animation asset id.

Weighted: boolean--

true for a looped, always-playing track blended by weight; false for a one-shot.

Priority: Enum.AnimationPriority?--

Default Enum.AnimationPriority.Movement for weighted, Action for one-shots.

Speed: number?--

Playback speed. Default 1.

}

One animation in the table given to NPCAnimator.new.

Functions​

new​

NPCAnimator.new(
entity: Model,--

Needs an Animator somewhere inside (usually under the Humanoid or AnimationController).

animations: {[string]: AnimationInfo}
) → NPCAnimator

Errors

TypeDescription
stringThe model has no `Animator`.

Load​

NPCAnimator.Load(self: NPCAnimator) → NPCAnimator

Loads every animation. Weighted tracks start playing at almost-zero weight so they blend in without a pop. Calling it twice does nothing.

SetWeight​

NPCAnimator.SetWeight(
self: NPCAnimator,
name: string,
weight: number,--

0 to 1. Clamped above zero so the track never drops out.

fade: number?--

Seconds to blend. Default 0.1.

) → NPCAnimator

Errors

TypeDescription
stringUnknown name, or the animation is not weighted.

Play​

NPCAnimator.Play(
self: NPCAnimator,
name: string,
fade: number?,
weight: number?,
speed: number?
) → NPCAnimator

Plays a one-shot.

Errors

TypeDescription
stringUnknown name, or the animation is weighted.

Stop​

NPCAnimator.Stop(
self: NPCAnimator,
name: string,
fade: number?
) → NPCAnimator

Stops a one-shot.

Errors

TypeDescription
stringUnknown name, or the animation is weighted.

GetTrack​

NPCAnimator.GetTrack(
self: NPCAnimator,
name: string
) → AnimationTrack

The loaded track, for anything the helpers do not cover (markers, TimePosition).

Errors

TypeDescription
stringUnknown name.

GetAnimations​

NPCAnimator.GetAnimations(self: NPCAnimator) → {[string]: AnimationInfo}--

The table given to new.

Destroy​

NPCAnimator.Destroy(self: NPCAnimator) → ()

Stops and destroys every track and the Animation instances it made.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "",
            "params": [
                {
                    "name": "entity",
                    "desc": "Needs an `Animator` somewhere inside (usually under the Humanoid or AnimationController).",
                    "lua_type": "Model"
                },
                {
                    "name": "animations",
                    "desc": "",
                    "lua_type": "{ [string]: AnimationInfo }"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "NPCAnimator"
                }
            ],
            "function_type": "static",
            "errors": [
                {
                    "lua_type": "string",
                    "desc": "The model has no `Animator`."
                }
            ],
            "source": {
                "line": 79,
                "path": "lib/Animator/init.luau"
            }
        },
        {
            "name": "Load",
            "desc": "Loads every animation. Weighted tracks start playing at almost-zero weight so they blend in\nwithout a pop. Calling it twice does nothing.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "NPCAnimator"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "NPCAnimator"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 138,
                "path": "lib/Animator/init.luau"
            }
        },
        {
            "name": "SetWeight",
            "desc": "",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "NPCAnimator"
                },
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "weight",
                    "desc": "`0` to `1`. Clamped above zero so the track never drops out.",
                    "lua_type": "number"
                },
                {
                    "name": "fade",
                    "desc": "Seconds to blend. Default `0.1`.",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "NPCAnimator"
                }
            ],
            "function_type": "static",
            "errors": [
                {
                    "lua_type": "string",
                    "desc": "Unknown name, or the animation is not weighted."
                }
            ],
            "source": {
                "line": 177,
                "path": "lib/Animator/init.luau"
            }
        },
        {
            "name": "Play",
            "desc": "Plays a one-shot.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "NPCAnimator"
                },
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "fade",
                    "desc": "",
                    "lua_type": "number?"
                },
                {
                    "name": "weight",
                    "desc": "",
                    "lua_type": "number?"
                },
                {
                    "name": "speed",
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "NPCAnimator"
                }
            ],
            "function_type": "static",
            "errors": [
                {
                    "lua_type": "string",
                    "desc": "Unknown name, or the animation is weighted."
                }
            ],
            "source": {
                "line": 199,
                "path": "lib/Animator/init.luau"
            }
        },
        {
            "name": "Stop",
            "desc": "Stops a one-shot.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "NPCAnimator"
                },
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "fade",
                    "desc": "",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "NPCAnimator"
                }
            ],
            "function_type": "static",
            "errors": [
                {
                    "lua_type": "string",
                    "desc": "Unknown name, or the animation is weighted."
                }
            ],
            "source": {
                "line": 219,
                "path": "lib/Animator/init.luau"
            }
        },
        {
            "name": "GetTrack",
            "desc": "The loaded track, for anything the helpers do not cover (markers, `TimePosition`).",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "NPCAnimator"
                },
                {
                    "name": "name",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "AnimationTrack"
                }
            ],
            "function_type": "static",
            "errors": [
                {
                    "lua_type": "string",
                    "desc": "Unknown name."
                }
            ],
            "source": {
                "line": 238,
                "path": "lib/Animator/init.luau"
            }
        },
        {
            "name": "GetAnimations",
            "desc": "",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "NPCAnimator"
                }
            ],
            "returns": [
                {
                    "desc": "The table given to `new`.",
                    "lua_type": "{ [string]: AnimationInfo }"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 246,
                "path": "lib/Animator/init.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Stops and destroys every track and the Animation instances it made.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "NPCAnimator"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 255,
                "path": "lib/Animator/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "AnimationInfo",
            "desc": "One animation in the table given to [NPCAnimator.new].",
            "fields": [
                {
                    "name": "Id",
                    "lua_type": "number",
                    "desc": "The animation asset id."
                },
                {
                    "name": "Weighted",
                    "lua_type": "boolean",
                    "desc": "`true` for a looped, always-playing track blended by weight; `false` for a one-shot."
                },
                {
                    "name": "Priority",
                    "lua_type": "Enum.AnimationPriority?",
                    "desc": "Default `Enum.AnimationPriority.Movement` for weighted, `Action` for one-shots."
                },
                {
                    "name": "Speed",
                    "lua_type": "number?",
                    "desc": "Playback speed. Default `1`."
                }
            ],
            "source": {
                "line": 31,
                "path": "lib/Animator/init.luau"
            }
        }
    ],
    "name": "NPCAnimator",
    "desc": "Plays and blends animations on an NPC rig by name.\n\n```lua\nlocal animator = VluxyAI.Animator.new(model, {\n\tIdle = { Id = 123, Weighted = true },\n\tWalk = { Id = 456, Weighted = true },\n\tSwing = { Id = 789, Weighted = false },\n}):Load()\n\nanimator:SetWeight(\"Walk\", 1)\nanimator:Play(\"Swing\")\n```\n\nLoad every animation up front in `Load`; adding tracks later is not supported.",
    "source": {
        "line": 71,
        "path": "lib/Animator/init.luau"
    }
}