Animations

(Redirected from Tutorial:Animations)

ROBLOX has introduced an Animation Editor plugin for ROBLOX Studio. This tool allows developers to design and publish custom animations. Animations can still be created without the plugin using Keyframe Sequences, but the Animation Editor is recommended for all projects going forward.

Contents

[edit] Using the Editor

[edit] Installation

The Animation Editor can be installed by logging into the ROBLOX website and installing the plugin. Alternatively, the plugin can be searched for in ROBLOX Studio by navigating to Tools > Manage Plugins > Find Plugins and searching for "Animation Editor". If you are using the ribbon style toolbar in Studio, Manage Plugins can be found under the Add-Ons tab.

Editing a pose in the Animation Editor

[edit] Launching the Editor

To launch the editor, click on the Animation Editor button AnimationEditorButton.png found in the toolbar. This will prompt you to select the base of the object you want to define animations for. This part must be named "HumanoidRootPart", and is already in the default player model as well as the four rigs that the editor provides.

After you select the base part, the editor window will open. This window shows a timeline and a list of all the parts in your model. At any place in the timeline you can create a keyframe where you can define how the model should look at that point in the animation. The position defined for each part in a keyframe is called a pose. When the animation runs, it will smoothly move parts between the poses defined in the keyframes.

* When the animation editor plays animations, it starts simulating the place environment, which includes executing server scripts. It is therefore recommended to do all animation work in an empty place to avoid any peculiar behaviors with all of your scripts running during animation testing.

[edit] Poses

To create a pose, drag the current keyframe indicator CurrentKeyframeIndicator.png to the point in the timeline where you want to define your pose. Then, click on the part of the model you want to manipulate. Using the "R" hotkey, you can switch between rotating or moving the part. Parts in poses can be rotated in 45 degree, 10 degree increments or can be freely rotated. Parts can be moved in 1 brick or .2 brick increments or can be freely moved.

Creating a pose will automatically create a keyframe in your timeline. Note that you can create multiple poses per each keyframe (at most one per part in your model). A pose in the editor will appear as a square on the keyframe PoseIndicator.png. You can also copy and paste poses in the editor. To do this, ctrl + click on the pose. Then, move the keyframe indicator to the point in the timeline you want the pose to be copied to and paste by pressing v. You can delete a pose by shift + right clicking on it.

[edit] Keyframes

To move a keyframe click and drag on the top of the keyframe in the timeline. This moves all poses that are in that keyframe.

To delete a keyframe shift + right click on the keyframe in the timeline and select "Delete". Note that the Animation Editor does not have an undo feature, so please be careful when deleting!

To rename a keyframe shift + right click on it in the timeline and select "Rename".

*Naming a keyframe allows you to bind a function to when that frame is reached. For instance, in a walking animation you could name the frames where the character's feet touch the ground and play a sound when those frames are reached. See KeyframeReached for more.

[edit] Priority

In your game you may have several different animations for player actions and states, but what happens when you want to start playing an animation when another is currently running? For instance, suppose you have a jump animation and an animation for when a character is standing still. To make the jump animation override the standing animation, priority should be used.

There are four levels of animation priority:

  • Core (lowest priority)
  • Idle
  • Movement
  • Action (highest priority)

If you start playing an animation with a higher priority than the one that was already playing, the new animation will supersede the old. You can set the priority in the editor while making an animation by clicking on the priority menu and selecting your desired level.

[edit] Exclusion

Priority handles how to override animation behavior, but sometimes it is desirable to have two animation running at the same time. For example, if you make a waving animation, you may want that animation to be able to run while a character is walking or standing. When making an animation in the editor, you can select certain parts to include in the animation. The box next to the part name designates whether or not to include that part in the animation (by default all parts are included). When you play your animation, any excluded parts will continue to do what they were doing before the animation started.

Example of an animation that ignores the character's legs.

[edit] Animation Length

Animations created in the editor are 2 seconds long by default but can be changed to be any length up to 30 seconds. To change the length of an animation in the editor, click on the last time label in the timeline. This will prompt you to enter a length in seconds. If you already have keyframes in your animation, they will stay in the same relative position. For instance, lets say you had an animation 2 seconds in length and had a keyframe at 1 second (halfway through they timeline). If you change the animation length to 3 seconds, the keyframe will remain at the halfway point and will trigger at 1.5 seconds.

[edit] Looping

When designing an animation in the editor, you can set the animation to automatically loop. The loop checkbox in the upper right corner of the editor will toggle looping on and off.

*If you make an animation loop, the animation does NOT interpolate between the last keyframe and first keyframe. Therefore, it is a good idea to make the last keyframe identical to your first keyframe to make sure that the animation loops smoothly.

[edit] Export

Once you are satisfied with your animation you can upload it to Roblox to use in your places. Click on the menu AnimationEditorMenu.png in the editor and select Export. Here you can either create a new animation or overwrite an existing one. After the animation has uploaded, make note of the asset id in the url that is provided:

AnimationAssetUrl.png

You can use this url to create an animation in a script as seen in Using Animation in Games.

[edit] Import

Animations can be imported into the Animation Editor to make tweaks and changes. Pressing the Import button in the editor will prompt for the Id of the animation. This is the numerical part of the animation's asset Id. Note that you can only import animations you have created. When you have finished changing the animation, you can export it again and overwrite the original animation or create a new one.

[edit] Menu

Pressing the menu button AnimationEditorMenu.png in the editor will give you the following options:

Name Description
Play Plays the animation for testing.
Save Makes a local save of the timeline. Note that this save is specific to the editor and is not used to load the animation in your places.
Load Loads a local save of the timeline.
Export Uploads your animation to Roblox.
Reset Clears the current timeline of all keyframes and poses.

[edit] Using Animation in Games

Animations can be added to a place either through a script or by adding an Animation object to the Workspace.

An animation object can be added to the Workspace by selecting Insert Basic Object > Animation AnimationObject.png. The only property that has to be set is the Animation Id:

AnimationSetId.png

An animation object can be created in a script by instantiating an Animation and then pointing it to the Animation Id you want to use.

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=144884906"

[edit] Playing Animation in Player Character

A model to be animated must have several parts to work. Firstly, it must have a Humanoid in which to load the animation itself with the LoadAnimation function. Secondly, it must also have a part called HumanoidRootPart. When it creates the animation from a timeline, the Animation Editor expects this part to exist. By default, player characters have both of these parts so only the animation has to be loaded in that case.

Loading the animation into a Humanoid creates an AnimationTrack which can then be played:

local animTrack = Humanoid:LoadAnimation(animation)
animTrack:Play()

Player character animations should be played from a LocalScript .

[edit] Playing Animation in Non-Player Character

Loading an animation into a Non-Player Character (or NPC) is almost the exact same as loading it into a Player Character. The main difference is that instead of loading the animation into a Humanoid part contained in the model, instead a NPC's animation should be loaded into an AnimationController. An Animation Controller can be added into the model through Insert Basic Object > AnimationController AnimationObject.png or in a script via Instance.new("AnimationController"). Note that the model still has to have a part called HumanoidRootPart (even if the model doesn't contain a Humanoid object).

Loading the animation into an AnimationController an AnimationTrack which can then be played:

local animController = Instance.new("AnimationController")
local animTrack = animController:LoadAnimation(animation)
animTrack:Play()

Non-Player Character animations should be played from a server Script.

[edit] Animating Custom Models

The Animation Editor can be used to create animations for custom models (not just the stock player character model), although this requires a bit more setup. The model still must have a part called HumanoidRootPart. The moving parts of the model must also all be connected with Motor6D parts. The HumanoidRootPart must also connect to the rest of the model via a Motor6D. The mesh rigs that the animation editor generates is a good example of the kind of part hierarchy to use:

DummyPartHierarchy.png

Just remember that if your model is intended for a player character, the animation must be loaded into a Humanoid and run with a LocalScript. If the model is for a NPC, then it should be loaded into an AnimationController and run with a server Script.

[edit] Example

This example shows how to play an animation on a player character when it touches a fence. Note that at the moment ROBLOX does not support sharing animations, so you will have to replace the animation ID with one you have made yourself. This may change in the future, so please periodically check the ROBLOX blog and development forums for any updates.

This example also makes use of the KeyframeReached event to handle playback of the animation. Above in Keyframes you can see how to name a keyframe in your animation to make use of this feature.

Select
-- Import animation
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=144911345"
 
-- Local variables
local animTrack = nil
local canPlay = true
 
function playShockAnim(Source)
	if canPlay then
		local player = game.Players.LocalPlayer.Character
		canPlay = false
		animTrack = player.Humanoid:LoadAnimation(animation) -- Load animation into Humanoid
		animTrack.KeyframeReached:connect(function(keyframeName) -- Bind function to KeyframeReached event
			if keyframeName == "ElectrocuteEnd" then
				canPlay = true
			end
		end)	
		animTrack:Play() -- Start the animation
	end
end

Sample Project

[edit] API

[edit] Animation

AnimationId - Gets and sets url to animation asset.

[edit] AnimationTrack

AdjustSpeed(float speed = 1) - Allows you to change the speed of an animation while it is playing.
Play() - Plays an animation from the beginning.
Stop() - Stops an animation.
KeyframeReached(string keyframeName) - Fires when animation reaches a new keyframe. keyframeName is the name of the current keyframe the animation has reached.

[edit] Humanoid

LoadAnimation(Animation animation) - Load animation into humanoid and returns an AnimationTrack for playback.

[edit] See also