Hi, been trying to use waypoints in my 3D engine for using some A.I. I have tried this code
function control_baddies()
for n=1 to baddiecounter
for diff =-1 to 1
if baddy[n].id>0
if getobjectx(baddy[n].id)+diff <getobjectx(waypoint[waypointtarget].id)
spdx#=0.01
//setobjectposition(baddy[n].id,getobjectx(baddy[n].id)+spdx#,getobjecty(baddy[n].id),getobjectz(baddy[n].id)+spdz#)
endif
if getobjectx(baddy[n].id)+diff>getobjectx(waypoint[waypointtarget].id)
spdx#=-0.01
//setobjectposition(baddy[n].id,getobjectx(baddy[n].id)+spdx#,getobjecty(baddy[n].id),getobjectz(baddy[n].id)+spdz#)
endif
if getobjectz(baddy[n].id)+diff >getobjectz(waypoint[waypointtarget].id)
spdz#=-0.01
endif
if getobjectz(baddy[n].id)+diff<getobjectz(waypoint[waypointtarget].id)
spdz#=0.01
//setobjectposition(baddy[n].id,getobjectx(baddy[n].id)+spdx#,getobjecty(baddy[n].id),getobjectz(baddy[n].id)+spdz#)
endif
if getobjectz(baddy[n].id)+diff=getobjectz(waypoint[waypointtarget].id) and getobjectx(baddy[n].id)+diff=getobjectx(waypoint[waypointtarget].id)
inc waypointtarget
print ("Arrived")
endif
print (str(getobjectx(baddy[n].id)))
setobjectposition(baddy[n].id,getobjectx(baddy[n].id)+spdx#,getobjecty(baddy[n].id),getobjectz(baddy[n].id)+spdz#)
endif
next diff
spdx#=0
spdz#=0
next n
endfunction
Which obviously is useless as this video shows:
I thought using that small for next of diff would do but not so, I dont think it well ever work.. So the baddie will never move onto the next waypoint
Can someone straighten me out and show me a better way to do this? I just want that baddy to get to the first way point then to the next and so on, I know I dont have a way to get back to waypoint 1 yet but I need to help in getting this right first.. tnx
Hail to the king, baby!