Thanks for helping but i want to use a function for the enemies
i have decided to stick with the enemy defending zones
i have since added this to load the enemies.
make object plain 13,0.3,1,1
xrotate object 13,90
fix object pivot 13
make mesh from object 2,13
delete object 13
for e = 501 to 503
Load object "media/AI.x",e
load image "media/ai_2_D2.dds",42
texture object e,42
make object e+1000,13,11
set object light e+1000,0
hide object e+1000
AI Add Enemy e
AI Set Entity Speed e,10.0
AI Set Entity View Arc e,90,170
AI Set Entity View Range e,50
AI Set Entity Can Strafe e,0
AI Set Entity Can Search e,0
AI Set Entity Stance e,1
next e
AI Add Zone 1,1000,-900,1300,-700
AI Entity Assign Zone 501,1
and in a function
currtime# = timer()
lasttime# = currtime#
currtime# = timer()
speed# = 0.06*(currtime# - lasttime#)
lasttime# = currtime#
position object 501,700,0,-2000
position object 502,1000,0,-2200
position object 503,1000,0,-1200
for e=1001 to 1003
if object exist(e) and shootTimer(e-1000)<70 then hide object e
next e
rem Call this command every sync to update entity AI state
AI Update
for e = 501 to 503
if AI Entity Exist(e)=1
if AI Get Entity Can Fire(e) and shootTimer(e)<=0
rem get the target position and place the attack line between them
tx# = AI Get Entity Target X(e)
tz# = AI Get Entity Target Z(e)
x# = object position x(e)
z# = object position z(e)
dx# = ( x# + tx# ) / 2.0
dz# = ( z# + tz# ) / 2.0
dist# = sqrt ( (tx#-x#)*(tx#-x#) + (tz#-z#)*(tz#-z#) )
ang# = acos ( (tz#-z#) / dist# )
if ( (tx#-x#) < 0 ) then ang# = 360 - ang#
position object e+1000,dx#,2.5,dz#
yrotate object e+1000,ang#+0.1
scale object e+1000,100,100,100*dist#
show object e+1000
shootTimer(e)=100
endif
endif
rem control how often the entity can shoot
if shootTimer(e)>0 then shootTimer(e) = shootTimer(e)-(speed#*3)
next e
ai has been added to the player as before and global dim shootTimer(3) as float has been defined at the top of the programme.
but the enemy ai are not repsonding.