I made, some time ago, a small snippet aiming at checking line of sight and player visibility.
hope it can help
Rem Project: EnemyLineOFsight
Rem Created: July 2006
Rem by Scorpyo
______Top________:
set display mode 1024,768,32
hide mouse
sync on
backdrop on
gosub Vars1
gosub Setupland1
gosub setambient
gosub makeobjects
gosub make_enemy
gosub Character
set global collision off
sync rate 60
set camera range 10,landsize*2
gosub Resetcam
sync
______Main_Loop______:
do
if inkey$()="c" and camflag=0 then gosub resetcam2:wait 200
if inkey$()="c" and camflag=1 then gosub resetcam:wait 200
gosub Playercontrol
gosub enemycontrol
gosub Printdata
gosub update_camera
gosub checkviewangle
gosub checksight
sync
loop
_____Sub_Routines_____:
Playercontrol:
px#=newxvalue(px#,py#,ps#)
pz#=newzvalue(pz#,py#,ps#)
ph#=get ground height(1,px#,pz#)
position object 9999,px#,ph#+5,pz#
yrotate object 9999,py#
if mouseclick()=0
mymousex=mousemovex()
if mymousex<0 then py#=wrapvalue(py#-4)
if mymousex>0 then py#=wrapvalue(py#+4)
endif
if inkey$()="w" and ps#<12 then ps#=ps#+2
if inkey$()="s" and ps#>-12 then ps#=ps#-2
if inkey$()="a" then py#=wrapvalue(py#-4)
if inkey$()="d" then py#=wrapvalue(py#+4)
if inkey$()="q" then ps#=0.0
return
enemycontrol:
ex#=newxvalue(ex#,ey#,es#)
ez#=newzvalue(ez#,ey#,es#)
eh#=get ground height(1,ex#,ez#)
position object 11,ex#,eh#+5,ez#
yrotate object 11,ey#
if upkey()=1 and es#<12 then es#=es#+2
if downkey()=1 and es#>-12 then es#=es#-2
if leftkey()=1 then ey#=wrapvalue(ey#-4)
if rightkey()=1 then ey#=wrapvalue(ey#+4)
if inkey$()="q" then es#=0.0
return
checkviewangle:
atangle#=atanfull(px#-ex#,pz#-ez#)
if atangle#<0
anglediff#=abs(atangle#)-abs(360-ey#)
if abs(anglediff#)<70
b$="WITHIN VIEW ANGLE"
else
b$="OUT OF VIEW ANGLE"
endif
endif
if atangle#>0
anglediff#=abs(atangle#)-abs(ey#)
if abs(anglediff#)<70
b$="WITHIN VIEW ANGLE"
else
b$="OUT OF VIEW ANGLE"
endif
endif
return
checksight:
for n=1 to 10
hidecheck#=intersect object(n,px#,10,pz#,ex#,10,ez#)
if hidecheck#>0 then a$="HIDDEN":return
if hidecheck#=0 then a$="NOT HIDDEN"
next n
return
Printdata:
set cursor 0,0
set text opaque
print "Polygons=",statistic(1)
print "Fps=",screen fps()
print
print "c = toggle camera follow"
print "w,a,s,d + mouse = player movement"
print "arrow keys = enemy movement"
print
print a$
print b$
return
rem **********CAMERA*****************
update_camera:
if inkey$()="z" then camdist=-1000:camhgt=800
if inkey$()="<" then gosub Resetcam
mymousez=mousemovez()
if mymousez>0 then camhgt=camhgt+10
if mymousez<0 then camhgt=camhgt-10
if mouseclick()=2
mymousey=mousemovey()
if mymousey>0 then camrot=camrot+5
if mymousey<0 then camrot=camrot-5
endif
if camfollow=1
ca#=wrapvalue(py#+camrot)
cx#=newxvalue(px#,ca#,camdist)
cz#=newzvalue(pz#,ca#,camdist)
cy#=get ground height(1,px#,pz#)
position camera cx#,cy#+camhgt,cz#
point camera px#,cy#+200,pz#
endif
return
Resetcam:
camdist=-600
camhgt=400
camrot=0
camfollow=1
camflag=0
return
resetcam2:
cx#=landsize/2:cz#=-1000
camhgt=2000
camrot=0
camfollow=0
camflag=1
position camera cx#,cy#+camhgt,cz#
point camera px#,cy#,pz#
return
_____Prepare_Scenery____:
Setupland1:
make matrix 1,landsize,landsize,grid,grid
randomize 1
randomize matrix 1,mtxrandomize
update matrix 1
return
setambient:
set ambient light 60
return
makeobjects:
randomize 3
for n=1 to 10
make object cube n,300
xpos#=rnd(landsize):zpos#=rnd(landsize)
position object n,xpos#,get ground height(1,xpos#,zpos#)+150,zpos#
next n
return
make_enemy:
make object cone 11,200
scale object 11,120,160,120
xrotate object 11,90
fix object pivot 11
set object cull 11,0
color object 11,rgb(255,0,0)
position object 11,landsize/2,50,landsize/2+1000
return
Character:
make object cone 9999,160
scale object 9999,120,160,120
xrotate object 9999,90
fix object pivot 9999
set object cull 9999,0
return
rem ********SOME VARIABLES ******
Vars1:
rem
mtxrandomize=1
landsize=10000
grid=10
rem **Player Start position**
px#=landsize/2-100
pz#=landsize/2-1000
py#=0.0
rem Enemy start positio
ex#=landsize/2
ez#=landsize/2+1000
es#=0
ey#=0.0
return
end