; SetAnimRootMotion 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 ; SetAnimRootMotion strips that movement out of the displayed pose and, ; with apply=True, moves the entity itself instead apply=True SetAnimRootMotion courier,"CourierRoot",apply,False,False ; Play the patrol ping-pong so the robot shuttles back and forth CrossFadeAnim courier,patrol,0,2 While Not KeyDown(1) ; Space re-calls SetAnimRootMotion with apply flipped: with apply=False ; the extracted movement is discarded and the robot marches on the spot If KeyHit(57) apply=1-apply SetAnimRootMotion courier,"CourierRoot",apply,False,False EndIf UpdateWorld ; 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,"Space: toggle apply Arrows: camera Esc: exit" Text 0,20,"SetAnimRootMotion courier,"+Chr$(34)+"CourierRoot"+Chr$(34)+","+apply+",False,False" Text 0,40,"Root delta X: "+AnimRootMotionX(courier)+" EntityX: "+EntityX(courier) Flip Wend End