hey, ive got a litle problem in some thing im making(just playing with some stuff).
only one "enemy" is following its waypoints, this is the first enemy loaded in.
ive made a waypoint editor, to place waypoints this is the routine that loads the positions in(nothing wrong with this(i hope)).
prepare_enemy_path_data:
wp=0
enemyNumber=0
for x= 1 to players(1)-1
enemyNumber=enemyNumber+1
file_path$="levelDATApathnumber"+str$(enemyNumber)+" level"+str$(level_id(1))+".dat"
if file exist(file_path$)=1
open to read 1,file_path$
`read current enemys path number and the total number off waypoints in that path
read string 1,h$ : pathnumber(enemyNumber)=val(h$)
read string 1,h$ : totalwaypoints(enemyNumber)=val(h$)
`Then opdate the waypoint() array to hold the position info, that we later on will use to move our enemy around the current level
if enemyNumber>1
REM after coding late night i forgot how i planned to make this work(hehe), so fund something else out
firstWayPoint(enemyNumber)=wp+1
else
if enemyNumber=1
firstWayPoint(1)=1
endif
endif
for temp=1 to totalwaypoints(enemyNumber)
add to queue waypoint()
next temp
`read the position off the waypoints into the correct dimension off the waypoint array
for n=1 to totalwaypoints(enemyNumber)
wp=wp+1
read string 1,h$ : waypoint(wp).id=val(h$)
read string 1,h$ : waypoint(wp).x#=val(h$)
read string 1,h$ : waypoint(wp).y#=val(h$)
read string 1,h$ : waypoint(wp).z#=val(h$)
next n
close file 1
endif
next x
this is the function that opdates to the next waypoint(i think that this is were the problem is)
FUNCTION get_next_waypoint(id,path,x#,y#,z#)
REM store values for current path , NOTE variable current represents the current waypoint
REM find the first waypoint in path, only if not fund before, this only needs to be done at the start up to any level
if current_waypoint(id)=0
current_waypoint(id)=firstWayPoint(id)
endif
dist_to_waypoint#(id)=get_dist#(x#,waypoint(current_waypoint(id)).x#,y#,y#,z#,waypoint(current_waypoint(id)).z#)
if dist_to_waypoint#(id) < 20
current_waypoint(id)=current_waypoint(id)+1
if current_waypoint(id) > totalwaypoints(path)
current_waypoint(id) = firstWaypoint(path)
endif
endif
ENDFUNCTION current_waypoint(id)
then the function for making the enemy face the next waypoint
i think im gonna do this using vectors later on, anyway:
FUNCTION control_ai_movement(id,wid)
REM find the angle between the enemyobject and the waypoint it is heading for, i first tryed this using vectors but something vent VERY wrong, just to bad
`get the distance to the waypoint enemy is suposed to be heading for
dist#=dist_to_waypoint#(id-1)
`then work out the enemys fov, for later check on, if its heding for the waypoint
wayPoint_fov#(id-1)=wrapvalue(atanfull(ox#(id)-waypoint(wid).x#,oz#(id)-waypoint(wid).z#))
if wayPoint_fov#(id-1)>180 then wayPoint_fov#(id-1)=wayPoint_fov#(id-1)-360
REM now check to see if waypoint is inside enemys fov
if abs(wayPoint_fov#(id-1)-oay#(id))>130 and abs(wayPoint_fov#(id-1)-oay#(id))<210
text screen width()/2,screen height()/2,"way point "+str$(wid)+" in field off view"
endif
REM then rotate it to face the next point, if so then move it forward, rotate faster if far away from waypoint
if abs(wayPoint_fov#(id-1)-oay#(id))>0 and abs(wayPoint_fov#(id-1)-oay#(id))<175
if dist_to_waypoint#(id-1) > 200
oay#(id)=oay#(id)+5
else
oay#(id)=oay#(id)+2.5
endif
endif
if abs(wayPoint_fov#(id-1)-oay#(id))>185 and abs(wayPoint_fov#(id-1)-oay#(id))<360
if dist_to_waypoint#(id-1) > 200
oay#(id)=oay#(id)-5
else
oay#(id)=oay#(id)-2.5
endif
endif
REM some thing wierd happens, the fov# some times goes over 360 and all the way up to 500+
REM tempuary solution
if abs(wayPoint_fov#(id-1)-oay#(id))>360
enemy(id-1).right=1
oay#(id)=oay#(id)+5
else
enemy(id-1).right=0
endif
if abs(wayPoint_fov#(id-1)-oay#(id))>175 and abs(wayPoint_fov#(id-1)-oay#(id))<185
forward(id)=1
else
forward(id)=0
endif
text 10,270,"fov1# = "+str$(abs(wayPoint_fov#(1)-oay#(2)))
text 10,280,"fov to player1= "+str$(abs(enemy(1).fov#-oay#(2)))
text 10,290,"current_waypoint(1)= "+str$(current_waypoint(1))
text 10,300,"dist_to_waypoint#(1)= "+str$(dist_to_waypoint#(1))
text 10,400,"fov2# = "+str$(abs(wayPoint_fov#(2)-oay#(3)))
text 10,410,"fov to player2= "+str$(abs(enemy(2).fov#-oay#(2)))
text 10,420,"current_waypoint(2)= "+str$(current_waypoint(2))
text 10,430,"dist_to_waypoint#(2)= "+str$(dist_to_waypoint#(2))
text 10,450,"wapoint 6 location= "+str$(waypoint(6).x#)+",0,"+str$(waypoint(6).z#)
text 10,460,"testing dist to waypoint 6= "+str$(get_dist#(ox#(3),waypoint(6).x#,oy#(3),oy#(3),oz#(3),waypoint(6).z#))
if downkey()=1 : back(id)=1 : else : back(id)=0 : endif
if leftkey()=1 : oay#(id)=oay#(id)-5 : endif
if rightkey()=1 : oay#(id)=oay#(id)+5 : endif
ENDFUNCTION
this is then called in the function that moves the enemys
current_waypoint(id-1)=get_next_waypoint(id-1,id-1,ox#(id),oy#(id),oz#(id))
control_ai_movement(id,current_waypoint(id-1))
BTW. ive searched the forum and did find some thing about waypoints,
so rigth now(when im done writeing this) im reading a paper called A* Pathfinding for Beginners by By Patrick Lester
the problem is that only enemy one, is moving. if i add any more enemy's they just move to their first waypoint and stay there.
if i change variable current_waypoint(number?) in the cli(the variable that holds the waypoint that the enemy is supposed to be heading for) to the next waypoint in its path, then it moves to that waypoint and turns around and moves back to its firstwaypoint. ah?
thx to any one who might figure it out.
BTW: (again)
im using the trail version of dbproo, have ordered the boxed version and got a mail that it was on its way yeah!
hehe
sorry for my english typeing
Still a noob. easy comes easy goes