Skip to content

CharacterBase

CharacterBase is a type of Entity which provides additional features for a humanoid character model in the game. This type is not spawned directly, it is instead used as a base class for other types like Character.

Functions

Function Name Usage Description Notes
Attach characterToAttachTo:Attach(Entity entityToAttach, string socketName) Attach an entity to this character using the given socketName (this is deprecated and will be removed, do entity:AttachTo(characterToAttachTo, socketName)) Deprecated, Server Only
SetAlive character:SetAlive(bool alive) For a Player set it to be alive (true) or dead (false). Server Only
IsAlive bool character:IsAlive() Get whether a Player is alive.
SetGrip character:SetGrip(GripAsset gripPresetAsset) Set the current grip animations used by this player. Passing nil is the same as calling SetNoGrip()
SetNoGrip character:SetNoGrip() Reverts the player back to the default 'unarmed' animations. Can also be achieved by calling SetGrip(nil)
PlayAction character:PlayAction(string actionName, table properties) Play an animation action, with properties specifying how it should be played
PlayAction character:PlayAction(string actionName) Play an animation action with default properties
HasAction bool character:HasAction(string actionName) Returns true if the current grip can perform this type of action
GetActions table character:GetActions() Get the name of every available action for this grip type
GetActionEvents table character:GetActionEvents(string actionName) Get the name of every event available event for an action
HasActionEvent bool character:HasActionEvent(string actionName, string eventName) Returns true if this action has an animation event of the specified name
GetPlayLength number character:GetPlayLength(string actionName) Returns the length of an animation, in seconds, assuming a playbackSpeed of 1 is set
Launch character:Launch(Vector impulse) Launch the character
AdjustAim AdjustAimHandle character:AdjustAim(... args) Adjust the character's aim from variable args. Each key is an angular velocity in degrees per second, followed by a Vector or Rotation. Specifying a vector will adjust the character's aim to point at that location. Specifying a rotator will adjust the character's aim by that amount relative to it's current rotation An optional easing type can be given for each key, which describes how to interpolate between the previous key and this one, from EaseIn, EaseOut, EaseInOut, Linear (default) The easing types can also be set per axis, this is described in one of the examples. Example Server Only, Local Only
CancelAdjustAim character:CancelAdjustAim(AdjustAimHandle handle) stop the current aim adjustment
IsAdjustAimActive bool character:IsAdjustAimActive() is any aim adjust active

Parameters

Parameter Name Usage Description Notes
speedMultiplier number speedMultiplier Multiplier on movement speed (default is 1.0)
jumpHeightMultiplier number jumpHeightMultiplier Multiplier on jump height (default is 1.0)
canSprint bool canSprint Turn on or off ability to sprint
canRun bool canRun Turn on or off ability to run
canWalk bool canWalk Turn on or off ability to walk
canMantle bool canMantle Turn on or off ability to mantle
maxMantleHeight number maxMantleHeight Set the maximum height that a player can mantle
canSlide bool canSlide Turn on or off ability to slide
canRelax bool canRelax Turn on or off ability to go into a grip's relaxed pose
breakFall bool breakFall Turn on or off ability to break fall on landing
breakFallSpeed number breakFallSpeed Turn on or off ability to break fall on landing
damageEnabled bool damageEnabled Turn on or off damage (ie calling of entry point OnDamaged).

Overrides

Override Name Usage Description Notes
new_index characterBase.var = object value

Examples

AdjustAimHandle character:AdjustAim(... args)

The following example shows a simple AdjustAim that will cause the character to look at two positions. This will play once when the code is executed. Each change of position is interpolated with EaseInOut.

self:GetEntity():AdjustAim(
  90.0,                     -- rotate at a speed of 90 degrees per second
  Vector.New(0, 0, 100),        -- look at this location
  "EaseInOut",
  180.0,
  Vector.New(100, 0, 100),
  "EaseInOut"
)
The following example shows an example using both position and rotation, as well as specifying different easing parameters per axis
self:GetEntity():AdjustAim(
  90.0,
  Vector.New(100, 0, 100),   -- rotate to face this location
  { pitch = "EaseOut", },   -- only easeinout on the pitch, yaw & roll will remain linear
  10.0,
  Rotation.New(45, 0, 0)   -- then slowly look up by 45 degrees
)
You can pass the values to AdjustAim as a table, allowing for procedural generation. This example generates a 360 degree spin broken up into four 90 degree rotations, with an easeinout over each 90 degree turn
local aimTable = {}
local sections = 4
for index = 1, sections do
    table.insert(aimTable, 45) -- rotate at 45 degrees/sec
    table.insert(aimTable,  Rotation.New(0, 360 / sections, 0), -- rotate 90 degrees (360 / 4)
    table.insert(aimTable, "easeinout")  -- smoothly turn during each 90 degree segment
)
end
self:GetEntity():AdjustAim(aimTable)