; EntityDistance Example ; ---------------------- Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,0,-10 light=CreateLight() RotateEntity light,45,45,0 ; A patrolling mine and a player ship mine=CreateSphere(16) ScaleEntity mine,0.5,0.5,0.5 EntityColor mine,255,0,0 player=CreateCone(16) PositionEntity player,-4,0,0 EntityColor player,0,200,255 While Not KeyDown(1) ; The mine patrols up and down PositionEntity mine,2,Sin(MilliSecs()/10.0)*2,0 ; Arrow keys steer the player ship If KeyDown(203) Then MoveEntity player,-0.1,0,0 If KeyDown(205) Then MoveEntity player,0.1,0,0 If KeyDown(200) Then MoveEntity player,0,0.1,0 If KeyDown(208) Then MoveEntity player,0,-0.1,0 ; Measure the distance between the two entities dist#=EntityDistance(player,mine) ; Proximity warning: the mine glows when the player gets close If dist<3 EntityColor mine,255,255,0 Else EntityColor mine,255,0,0 EndIf RenderWorld Text 0,0,"Arrow keys: fly the ship near the mine Esc: exit" Text 0,20,"EntityDistance(player,mine) = "+dist Flip Wend End