; AttachToBone Example ; -------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,2,-6 RotateEntity camera,12,0,0 light=CreateLight() RotateEntity light,45,45,0 ; A grassy paddock for the fox to roam ground=CreatePlane() EntityTexture ground,LoadTexture("media/MossyGround.BMP") ; Load the rigged fox; its skinned mesh is driven by a bone skeleton fox=LoadAnimMesh("../../../samples/glTF/assets/Fox/Fox.glb") If fox=0 Then RuntimeError "Could not load Fox.glb: "+ModelLoadError() ; Shrink the fox to game scale (the file is modelled about 100 units tall) FitMesh fox,-0.8,0,-0.8,1.6,1.6,1.6,True ; A glowing lantern for the fox to carry lantern=CreateSphere(8) ScaleEntity lantern,0.08,0.08,0.08 EntityColor lantern,255,220,60 EntityFX lantern,1 ; AttachToBone parents the lantern to the fox's right hand bone, so the ; walk and run animations swing it around like a carried prop If AttachToBone(lantern,fox,"b_RightHand_08")=0 Then RuntimeError "Hand bone not found" ; Small local offset from the bone PositionEntity lantern,0,0.1,0 ; Start the fox walking PlayAnim fox,"Walk",0 While Not KeyDown(1) ; Switch clips to see the lantern follow the hand in each one If KeyHit(2) Then PlayAnim fox,"Survey",10 If KeyHit(3) Then PlayAnim fox,"Walk",10 If KeyHit(4) Then PlayAnim fox,"Run",10 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,"1/2/3: Survey/Walk/Run Arrows: camera Esc: exit" Text 0,20,"AttachToBone fixed the yellow lantern to bone "+Chr$(34)+"b_RightHand_08"+Chr$(34) Flip Wend End