I am trying to make an AI that moves around a maze and doesn't go through the walls. So far, I've tried using static lines and boxes to detect walls and than rotate the object away so it goes in a different direction.
sync on
sync rate 40
harrypotter = 0
make object plain 666,25,25
position object 666,0,0,-50
make object plain 2,50,50
position object 2,0,0,25
posx#=object position x(2)
posy#=object position y(2)
posz#=object position z(2)
make static collision box posx#,posy#,posz#,posx#,posy#,posz#
make object plain 3,50,50
position object 3,-25,0,0
yrotate object 3,270
posx#=object position x(3)
posy#=object position y(3)
posz#=object position z(3)
make static collision box posx#,posy#,posz#,posx#,posy#,posz#
make object plain 4,50,50
position object 4,100,0,0
yrotate object 4,270
posx#=object position x(4)
posy#=object position y(4)
posz#=object position z(4)
make static collision box posx#,posy#,posz#,posx#,posy#,posz#
gup=1
gright=0
gleft=0
Do
posx#=object position x(666)
posy#=object position y(666)
posz#=object position z(666)
move object 666,1
if object angle y(666)=0
if static line of sight(posx#,posy#,posz#,posx#,posy#,posz#+25,5,1)=1
gup=0
else
gup=1
ENDIF
if static line of sight(posx#,posy#,posz#,posx#+25,posy#,posz#,5,1)=0
gright=1
else
gright=0
ENDIF
if static line of sight(posx#,posy#,posz#,posx#-25,posy#,posz#,5,1)=0
gleft=1
else
gleft=0
ENDIF
if gup = 1 then goto lr
gtotal = gright + gleft
if gup = 0
if gtotal = 0
yrotate object 666,180
goto skip
ENDIF
ENDIF
if gtotal = 0 then goto skip
lr:
grand=rnd(gtotal)
if grand = 0 then goto skip
if grand = 1
if gright = 1 then yrotate object 666,90
ENDIF
if grand = 2
if gleft = 1 then yrotate object 666,270
ENDIF
goto skip
ENDIF
if object angle y(666)=90
if static line of sight(posx#,posy#,posz#,posx#+25,posy#,posz#,5,1)=1
gup=0
else
gup=1
ENDIF
if static line of sight(posx#,posy#,posz#,posx#,posy#,posz#-25,5,1)=0
gright=1
else
gright=0
ENDIF
if static line of sight(posx#,posy#,posz#,posx#,posy#,posz#+25,5,1)=0
gleft=1
else
gleft=0
ENDIF
if gup = 1 then goto lr
gtotal = gright + gleft
if gup = 0
if gtotal = 0
yrotate object 666,270
goto skip
ENDIF
ENDIF
if gtotal = 0 then goto skip
Labellr:
grand=rnd(gtotal)
if grand = 0 then goto skip
if grand = 1
if gright = 1 then yrotate object 666,180
ENDIF
if grand = 2
if gleft = 1 then yrotate object 666,0
ENDIF
goto skip
ENDIF
skip:
if upkey()=1
move camera 2.5
endif
if downkey()=1
move camera -2.5
endif
cx#=wrapvalue(cx#+mousemovey())
cy#=wrapvalue(cy#+mousemovex())
cz#=wrapvalue(cz#+mousemovez())
rotate camera cx#,cy#,cz#
sync
Loop
However, I have had no luck! It's getting very frustrating. Could someone please help me out with this or give an alternative?
Bio Fox...four guys, one computer, games like nobody's business.