|
src_entity - source entity handle dest_entity - destination entity handle |
|
Returns true if two entities can 'see' each other - a line-of-sight check. A straight line is traced between the two entities' positions. If nothing blocks it, the result is true. This is the classic 'can the guard see the player?' test - combine it with EntityDistance and a facing check for a complete AI sight test. Only entities that can block the line count as obstacles: an entity gets in the way if it has a pick mode set with EntityPickMode and its obscurer flag left on (the default). Walls and scenery you want to block sight lines must therefore be made pickable; entities with no pick mode are ignored, and so are the two entities being tested. The check runs from centre to centre. Since positions are entity origins, a low origin (at the feet of a character, say) can make the line skim the ground - consider testing from a pivot at eye height for character sight checks. See also: EntityPickMode, EntityInView, LinePick, EntityDistance. |
; EntityVisible Example
; ---------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
AmbientLight 200,200,200
; A scout that the player moves, and a target it is trying to watch
scout=CreateSphere(16)
ScaleEntity scout,0.25,0.25,0.25
PositionEntity scout,-2,0,5
EntityColor scout,0,255,0
target=CreateSphere(16)
ScaleEntity target,0.25,0.25,0.25
PositionEntity target,2,0,5
EntityColor target,0,128,255
; A wall between them - only PICKABLE entities block the line of sight
wall=CreateCube()
ScaleEntity wall,0.15,1.5,1.5
PositionEntity wall,0,0,5
EntityColor wall,255,0,0
EntityPickMode wall,2
While Not KeyDown(1)
; Arrow keys move the green scout
If KeyDown(203) Then MoveEntity scout,-0.1,0,0
If KeyDown(205) Then MoveEntity scout,0.1,0,0
If KeyDown(200) Then MoveEntity scout,0,0.1,0
If KeyDown(208) Then MoveEntity scout,0,-0.1,0
; Update the world so the visibility test uses current positions
UpdateWorld
; Line-of-sight test: can the scout see the target past the wall?
visible=EntityVisible(scout,target)
RenderWorld
Text 0,0,"Arrow keys: move the green scout Esc: exit"
Text 0,20,"EntityVisible(scout,target) = "+visible
If visible
Text 0,40,"The scout can see the target"
Else
Text 0,40,"The red wall blocks the view"
EndIf
Flip
Wend
End