Blitz3D+ Command Reference

AnimRootMotionZ# ( entity )

Parameters

entity - handle of an animated entity

Description

Returns the forward root-motion distance the last UpdateWorld produced.

Z is the entity own forward axis in local model space, so this is the one that carries most of a walk or run - the distance the animator built into the stride. Add it to the character position each update and the feet stop skating, because the model now travels at exactly the speed it was animated to travel.

It is a per-update delta rather than a running total. Divide it by the elapsed value you passed to UpdateWorld to get a real speed, which is handy for choosing when to blend from a walk into a run.

Reverse and ping-pong playback report signed values in the direction actually travelled, so a backwards-played walk gives you negative forward motion as you would expect. During a crossfade the displacement is blended between the two clips, which is what stops a character lurching when it changes gait. The result is 0 when root motion is off.

See also: AnimRootMotionX, AnimRootMotionY, AnimRootMotionYaw, SetAnimRootMotion.

Example

; AnimRootMotionZ Example
; -----------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,-6,3,0
RotateEntity camera,15,-90,0

light=CreateLight()
RotateEntity light,45,45,0

ground=CreatePlane()
EntityTexture ground,LoadTexture("media/MossyGround.BMP")

; A courier robot: a named pivot with a cube body
courier=CreatePivot()
NameEntity courier,"CourierRoot"
body=CreateCube(courier)
ScaleEntity body,0.4,0.4,0.6
PositionEntity body,0,0.4,0
EntityColor body,60,220,255

; Author a patrol animation whose keys carry the robot 8 units along Z
PositionEntity courier,0,0,-4
SetAnimKey courier,0
PositionEntity courier,0,0,4
SetAnimKey courier,60
patrol=AddAnimSeq(courier,60)
PositionEntity courier,0,0,-4

; Extract the movement as root motion and let it drive the entity
SetAnimRootMotion courier,"CourierRoot",True,False,False

; Play the patrol ping-pong so the robot shuttles back and forth
CrossFadeAnim courier,patrol,0,2

While Not KeyDown(1)

    UpdateWorld

    ; AnimRootMotionZ reports the Z movement extracted by this UpdateWorld;
    ; its sign flips when the ping-pong patrol reverses
    delta_z#=AnimRootMotionZ(courier)

    ; Arrow keys move the camera
    If KeyDown(200) Then MoveEntity camera,0,0,0.1
    If KeyDown(208) Then MoveEntity camera,0,0,-0.1
    If KeyDown(203) Then TurnEntity camera,0,1,0
    If KeyDown(205) Then TurnEntity camera,0,-1,0

    RenderWorld

    Text 0,0,"Arrows: camera   Esc: exit"
    Text 0,20,"AnimRootMotionZ(courier) = "+delta_z+" this frame"
    Text 0,40,"EntityZ: "+EntityZ(courier)

    Flip

Wend

End

Index