Here is an enemy FOV function:
Rem Dark Basic Classic Project:
Rem Created: 25/08/2005 17:18:25
Rem Author: Sven
Rem E-Mail: svenboulanger@hotmail.com
Rem Web Site:
Rem ***** Main Source File *****
sync on : sync rate 80
`make target object
make object plain 2,10,10
position object 2,20,0,20
`make player object
make object cube 1,2
do
`get player data
posx# = object position x(1)
posy# = object position y(1)
posz# = object position z(1)
angy# = object angle y(1)
`controls
if upkey() = 1
posx# = newxvalue(posx#,angy#,1)
posz# = newzvalue(posz#,angy#,1)
endif
if leftkey() = 1
yrotate object 1,wrapvalue(angy# - 1)
endif
if rightkey() = 1
yrotate object 1,wrapvalue(angy# + 1)
endif
`position
position object 1,posx#,posy#,posz#
chase_cam(1)
text 5,5,str$(raycast(1,2,30.0))
point object 2,posx#,posy#,posz#
sync
loop
`the function
function chase_cam(id)
posx# = object position x(id)
posy# = object position y(id)
posz# = object position z(id)
angy# = wrapvalue(object angle y(id) - 180)
camx# = newxvalue(posx#,angy#,10.0)
camz# = newzvalue(posz#,angy#,10.0)
camy# = posy# + 10.0
camx# = curvevalue(camx#,camera position x(),15)
camy# = curvevalue(camy#,camera position y(),15)
camz# = curvevalue(camz#,camera position z(),15)
position camera camx#,camy#,camz#
point camera posx#,posy# + 5.0,posz#
endfunction
function raycast(id,targetid,fv#)
`get players data
posx# = object position x(id)
posz# = object position z(id)
angy# = object angle y(id)
`get target data
targx# = object position x(targetid)
targz# = object position z(targetid)
sizex# = object size x(targetid)
tangy# = object angle y(targetid)
`calculating
diffang# = atanfull( targx# - posx#, targz# - posz# )
`check for ray casting
ray = 0
if angy# < wrapvalue(diffang# + fv#) and angy# > wrapvalue(diffang# - fv#)
ray = 1
endif
endfunction ray
You can determine the enemy's fov and it will tell you if it sees the target.
Immunity and Annihalation makes Immunihalation...