Animation and rigs
A character plays clips - a wave, a dance, a sword swing, sitting - over its own moves. A rig is a model of your own - a creature, a machine, a windmill - held together by Bones and moved by the same clips.
Playing a clip on a character
An Animation object holds a clip. Insert one (Insert Object > Animation), pick Start from in the Inspector for one of KHIM's clips, and shape it in the animation editor. Then:
local track = player.character.body:loadAnimation(world.Wave)
track:play()
track.stopped:connect(function() print("waved") end)| Track member | |
|---|---|
play(fadeTime?, weight?, speed?) | Starts it (again from the beginning if it was playing) |
stop(fadeTime?) | Stops it |
adjustSpeed(speed), speed | 1 as made, 0 holds still, at most 10 |
looped | Goes round and round |
playing, length, timePosition | Read-only |
stopped (also ended) | Fires when it stops or reaches its end |
body:getPlayingAnimationTracks() lists what is playing. Load an Animation once and play its track again; don't load it every time.
Who sees it: a Script's clip plays for every player. A ClientScript's clip on the player's own character is sent on to everyone too; on someone else's character, only that player sees it.
KHIM's own clips
animation.preset = "dance" (or Start from in the Inspector) fills an Animation with one of KHIM's clips: wave, dance, cheer, point, salute, laugh, shrug, sit, bow, clap - the emotes players type as /e dance - and idle, walk, jump, fall, climb, to start your own moves from.
Replacing the character's moves
A character is always doing one of five moves - Idle, Walk, Jump, Fall, Climb - and each is a clip. Give it your own:
local body = player.character.body
body.walkAnimation = world.Moves.Run -- also idleAnimation, jumpAnimation, fallAnimation, climbAnimation
body.walkAnimation = nil -- KHIM's own againYour clip takes over the joints it has keys for; KHIM's keeps the rest (a run that only moves the arms still has the walk's legs). The walk plays as fast as the character moves.
The animation editor
View > Animation, or Open the animation editor in an Animation's Inspector.
- The figure shows your character in the clip's pose at the playhead. Drag a joint's dot to turn that body part - it becomes a key at the playhead. Or use the Move and Rotate handles.
- The numbers at the top right: the picked joint's X, Y and Z at the playhead. Add a key, Remove the key, and how it eases to the next key: Smooth, Linear, Constant, Ease in, Ease out, Bounce, Elastic.
- The timeline: a row per joint, a mark per key. Drag a key to move it; double-click a row to add one; right-click for its ease or to remove it.
- Play runs the clip; Looped makes it go round.
- Copy pose, Paste pose and Mirror (left and right swapped) work a whole pose at a time.
Every change is one Undo step.
A clip is text
An Animation's keyframes is plain text - a key a line, or ; between keys:
0 RightArm 0 0 0
0.3 RightArm -160 0 20 smooth
0.6 RightArm -120 0 40
0.9 RightArm -160 0 20
1.2 RightArm 0 0 0Each key is seconds joint x y z [ease]. A character's joints are Root, Torso, Head, LeftArm, RightArm, LeftLeg, RightLeg; the numbers are degrees about the character's own axes (Root is in units: 0 Root 0 -1 0 is a step lower). A joint with no keys is left to the character, so the legs walk on under a wave. Limits: 512 keys, 60 seconds, 8,192 characters.
Rigs and Bones
A Bone holds one part to another - its holder - and turns it about a point: a creature's leg, a wing, a puppet's arm, a windmill's sails.
Making one in KHIM Engine: select the holder, Ctrl-click the part that moves, then insert Bone (Insert Object > Joints). The Bone goes on the part picked last.
| Bone member | |
|---|---|
holder | The part that carries it |
anchor | The point it turns about, in units from its part's middle, along the part's own directions |
angles | Its turn there, in degrees |
offset | Moves the part from where it stood |
enabled | Off: lets go |
Move or turn the holder - a script, a Motion, another Bone - and the part goes with it. A part inside a boned part with no Bone of its own rides along (a hat inside a head).
-- a Script inside the dragon Model
local dragon = script.parent
dragon.Head.Bone.angles = vec3(0, 30, 0) -- turn by hand: it looks to its left
dragon.Jaw.Bone.offset = vec3(0, -0.4, 0) -- the jaw drops
local flap = dragon:loadAnimation(dragon.Flap)
flap:play()A rig's clip names the rig's parts as joints - a part called "Left Wing" is LeftWing:
0 LeftWing 0 0 0
0.4 LeftWing 0 0 50
0.8 LeftWing 0 0 0Piston:move keys move a part instead of turning it (units). Keep a rig's Animations inside the rig, and the animation editor shapes them on the rig itself.
A Spring setting (0 stiff to 1 loose) on a Bone makes its part trail behind its pose - a tail, ears, a cape.
Your own player body
Name a rig StarterCharacter, build it facing +Z, keep it in ReplicationService, and give it Animations named Idle, Walk, Jump, Fall, Climb: every player is drawn as it. See Players and characters.
From Blender
Insert > Rig from Blender (.glb) brings a whole moving model at once: each mesh object a MeshPart, each held by a Bone where its bone is, and each Blender action an Animation. In Blender, parent each piece to its bone (Ctrl+P > Bone) and export glTF Binary with Animation ticked. Skinned meshes come in at their rest pose.