; AnimRootMotionY Example ; ----------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,2,-8 RotateEntity camera,8,0,0 light=CreateLight() RotateEntity light,45,45,0 ground=CreatePlane() EntityTexture ground,LoadTexture("media/MossyGround.BMP") ; A spring-loaded robot: a named pivot with a cube body hopper=CreatePivot() NameEntity hopper,"HopperRoot" body=CreateCube(hopper) ScaleEntity body,0.4,0.4,0.4 PositionEntity body,0,0.4,0 EntityColor body,255,180,60 ; Author a hop: keys that lift the robot 2 units up and drop it back PositionEntity hopper,0,0,0 SetAnimKey hopper,0 PositionEntity hopper,0,2,0 SetAnimKey hopper,15 PositionEntity hopper,0,0,0 SetAnimKey hopper,30 hop=AddAnimSeq(hopper,30) PositionEntity hopper,0,0,0 ; Vertical root motion is only extracted when the vertical flag is True SetAnimRootMotion hopper,"HopperRoot",True,True,False ; Loop the hop forever CrossFadeAnim hopper,hop,0,1 While Not KeyDown(1) UpdateWorld ; AnimRootMotionY reports the vertical movement extracted by this ; UpdateWorld: positive going up, negative coming down delta_y#=AnimRootMotionY(hopper) ; 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,"AnimRootMotionY(hopper) = "+delta_y+" this frame" Text 0,40,"EntityY: "+EntityY(hopper) Flip Wend End