; EntityParent Example ; -------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,6,-10 RotateEntity camera,25,0,0 light=CreateLight() RotateEntity light,45,45,0 ; A truck that drives in a circle truck=CreateCube() ScaleMesh truck,1,0.5,1.5 EntityColor truck,0,150,255 PositionEntity truck,4,0,0 ; A crate sitting in the middle of the yard crate=CreateCube() ScaleMesh crate,0.5,0.5,0.5 EntityColor crate,0,255,0 attached=0 While Not KeyDown(1) ; Space toggles the crate's parent between the truck and none If KeyHit(57) If attached ; Parent 0 releases the crate; it keeps its global position EntityParent crate,0 attached=0 Else ; Attach the crate: from now on it moves with the truck EntityParent crate,truck attached=1 EndIf EndIf ; Drive the truck in a circle TurnEntity truck,0,1,0 MoveEntity truck,0,0,0.08 ; 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: attach/release the green crate Arrow keys: move camera Esc: exit" If attached Text 0,20,"EntityParent crate,truck - the crate moves with the truck" Else Text 0,20,"EntityParent crate,0 - the crate is released where it is" EndIf Flip Wend End