| entity - handle of an animated entity |
|
Returns the sideways root-motion distance the last UpdateWorld produced. The value is in the entity own local model space, so X is the character sideways axis - the one that carries strafes and sidesteps. It is a delta for that single update, not a running total, so read it every frame and add it to your movement rather than expecting it to accumulate. The usual shape is a line straight after your update: TranslateEntity player,AnimRootMotionX(player),0,AnimRootMotionZ(player) which moves the character by exactly the distance the animator baked into the clip. If you set root motion up with apply True the engine has already done this for you, and reading the values is then only useful for driving footstep dust, working out real speed, or feeding a physics body. Reverse and ping-pong playback give signed values in the direction actually travelled, and loops use the clip end-to-start displacement rather than snapping backwards. The result is 0 when root motion is off. See also: AnimRootMotionZ, AnimRootMotionY, AnimRootMotionYaw, SetAnimRootMotion. |
; AnimRootMotionX Example
; -----------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,3,-8
RotateEntity camera,15,0,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 X
PositionEntity courier,-4,0,0
SetAnimKey courier,0
PositionEntity courier,4,0,0
SetAnimKey courier,60
patrol=AddAnimSeq(courier,60)
PositionEntity courier,-4,0,0
; 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
distance#=0
While Not KeyDown(1)
UpdateWorld
; AnimRootMotionX reports the X movement extracted by this UpdateWorld;
; its sign flips when the ping-pong patrol reverses
delta_x#=AnimRootMotionX(courier)
distance=distance+Abs(delta_x)
; 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,"AnimRootMotionX(courier) = "+delta_x+" this frame"
Text 0,40,"Distance walked: "+distance+" EntityX: "+EntityX(courier)
Flip
Wend
End