Hello i am working at the tutorial on this site (Limit Rush).
But I have some problems with the ai. The problem is that the ai ist standing there and do nothing but I do nothing and my hovercraft are runni gto the next hotspot ? I don't know what to do since sunday can someone help me please ? I am at Lesson 17 here is the Link http://developer.thegamecreators.com/?f=t02/bm_tutorial_42
and my code.
`--------
`INCLUDES
`--------
`Füge die LoadMatrix dba datei ein
#include "LoadMatrix.dba"
`------
`ARRAYS
`------
`Füge die matrix varis ein
Dim BigMatrix(600,600,1)
Dim StartLoc_X(1): Dim StartLoc_Z(1):Dim Info(2)
Dim TArrayX(1): Dim TArrayZ(1): Dim FKey(10,1)
Dim ColData(100): Dim ZoneData(100): Dim Tiles(500,500)
Dim OverTexture$(100): Dim OverName$(20): Dim ReplaceTex(100)
Dim MOffsetX(25): Dim MOffsetY(25)
Dim MWire(20): Dim MGhost(20): Dim Lock(20)
Dim MatX#(20): Dim MatY#(20): Dim MatZ#(20)
Dim MatWidth#(20): Dim MatHeight#(20)
Dim TilesX(20): Dim TilesZ(20)
Dim MatHi#(20): Dim MatLo#(20)
`spieler varis
dim xSpeed#(4)
dim ySpeed#(4)
dim zSpeed#(4)
dim friction#(4)
dim movedist#(4)
dim targetCount(4)
`gravitation
dim gravity#(0) : gravity#(0)=0.1
`hotspot data
dim hotspot(0)
dim oldHotspot(0)
`stelle spielgrundeinstellungen ein
set display mode 1024,768,16
sync on
sync rate 60
hide mouse
autocam off
`-------------
`level loading
`-------------
`lade map
LoadMatrix("map",1)
`lade arena
load object "media/arena.3ds",100
load object "media/arena_light.3ds",101
`mip-mapping
set matrix texture 1,2,1
set object texture 100,0,1
set object texture 101,2,1
`erstelle fakelights
set object 101,1,1,0,1,0,0,1
ghost object on 101
`erstelle nebel(fog)
fog on
fog distance 2000
fog color RGB(128,0,0)
`verändere weltlicht
set ambient light 10
`ändere die farbe von licht 0
color light 0,RGB(0,0,160)
`erstelle ein licht
make light 1
set point light 1,250,200,250
color light 1,RGB(255,255,100)
`--------------------
`Lade das SpecialEffect Licht
`--------------------
load object "media/light_beam.3ds",200
load object "media/light_beam2.3ds",201
make object plain 202,175,175
load image "media/light_3.bmp",1
texture object 202,1
set object rotation zyx 202
ghost object on 200
ghost object on 201
ghost object on 202
set object 200,1,1,0,1,0,0,1
set object 201,1,1,0,1,0,0,1
set object 202,1,1,0,1,0,0,1
`Erstelle Licht
make light 3
set point light 3,0,0,0
color light 3,RGB(0,128,255)
set light range 3,1000
`---------------
`schalte col aus
`---------------
set object collision off 200
set object collision off 201
set object collision off 202
set object collision off 100
set object collision off 101
`------------
`Lade Spieler
`------------
restore data_player_positions
for hc=1 to 4
make object cube hc,1
hide limb hc,0
textureName$="media/hovercraft_"+str$(hc)+".bmp"
load object "media/hovercraft.3ds",10+hc
load image textureName$,1
texture object 10+hc,1
scale object 10+hc,200,200,200
set object texture 10+hc,0,1
glue object to limb 10+hc,hc,0
`rechne pos der pl aus
read xPos#
read zPos#
yPos#=get ground height(1,xPos#,zPos#)
`rechne ang der pl aus
read yAng
`Update die pl posis
position object hc,xPos#,yPos#,zPos#
yrotate object hc,yAng
friction#(hc)=0.97
moveDist#(hc)=0.065
xSpeed#(hc)=0
zSpeed#(hc)=0
read friction#(hc)
read moveDist#(hc)
targetCount(hc)=0
make object collision box hc,-3,0,-3,3,4,3,0
next hc
new_target()
`---------
`MAIN LOOP
`---------
main:
do
`steuerung
if upkey()=1 then forward=1 else forward=0
if downkey()=1 then backward=1 else backward=0
if leftkey()=1 then left=1 else left=0
if rightkey()=1 then right=1 else right=0
`update pl
move_player(1,forward,backward,left,right)
for npc=2 to 4
control_player(1)
next npc
for pk=1 to 4
if checkHotspot(pk)=hotSpot(0)
new_target()
targetCount(pk)=targetCount(pk)+1
if targetCount(pk)=10 then end_game()
endif
next pk
`update cam
chase_cam(1)
text 10,10,str$(screen fps())
if checkHotspot(1)=hotSpot(0)
new_target()
targetCount(1)=targetCount(1)+1
if targetCount(1)=10 then end_game()
endif
gosub UPDATE_TARGET
gosub UPDATE_COLL
sync
loop
`animiere das specialeffect licht
UPDATE_TARGET:
yrotate object 200,wrapvalue(object angle y(200)+2)
yrotate object 201,wrapvalue(object angle y(201)-2)
point object 202,camera position x(),camera position y(),camera position z()
return
`update col daten
UPDATE_COLL:
for col=1 to 4
xPos#=object position x(col)
yPos#=object position y(col)
zPos#=object position z(col)
collision=object collision(col,0)
if collision>0
xPos#=xPos#-(get object collision x()/2)
zPos#=zPos#-(get object collision z()/2)
endif
Position object col,xPos#,yPos#,zPos#
next col
return
`-------------
`End game loop
`-------------
function end_game()
repeat
text 10,30,"Herzlichen Glückwunsch du hast Gewonnen"
text 10,50,"Bei Fragen einfach eine mail an Genetic@msn.de schicken"
text 10,70,"Drücke Space um das Spiel zu beenden"
sync
until spacekey()=1
end
endfunction
`-----------------------------
`setze eine neue pos für ziel
`-----------------------------
function new_target()
repeat
hotSpot(0)=rnd(7)+1
until hotspot(0)<>oldHotspot(0)
oldHotspot(0)=hotspot(0)
xPos=(FKey(hotspot(0),0)*info(0))-(info(0)/2)
zPos=(Fkey(hotspot(0),1)*info(1))-(info(1)/2)
yPos=get ground height(1,xPos,zPos)
position object 200,xPos,yPos,zPos
position object 201,xPos,yPos,zPos
position object 202,xPos,yPos,zPos
position light 3,xPos,yPos+5,zPos
endfunction
`---------
`chase cam
`---------
function chase_cam(1)
`rechne die ang des pl aus
yAng#=wrapvalue(object angle y(1)+180)
`rechne die derzeitige pos der cam aus
xPos#=object position x(1)
yPos#=object position y(1)
zPos#=object position z(1)
`cam varis
camDist=15
camHeight=3
`rechne neue pos aus
xCamPos#=newxvalue(xPos#,yAng#,camDist)
zCamPos#=newZvalue(zPos#,yAng#,camDist)
`cam col
if xCamPos#>499 then xCamPos#=499
if zCamPos#>499 then zCamPos#=499
if xCamPos#<1 then XCamPos#=1
if zCamPos#<1 then zCamPos#=1
`rechne camheight aus
yCamPos#=get ground height(1,xCamPos#,zCamPos#)+camHeight
if yCamPos#<yPos#+camHeight then yCamPos#=yPos#+camHeight
xCamPos#=curvevalue(xCamPos#,camera position x(),4)
yCamPos#=curvevalue(yCamPos#,camera position y(),4)
zCamPos#=curvevalue(zCamPos#,camera position z(),4)
`update cam pos
position camera xCamPos#,yCamPos#,zCamPos#
point camera xPos#,yPos#+camHeight,zPos#
endfunction
`-------------
`pl bewegungen
`-------------
function move_player(1,forward, backward, left, right)
`----------------------------------
`suche mir die benötigte daten raus
`----------------------------------
xPos#=object position x(1)
yPos#=object position y(1)
zPos#=object position z(1)
yAng#=object angle y(1)
`-----------------------------
`erstelle die basis bewegungen
`-----------------------------
`vorfärts
if forward=1
xSpeed#(1)=xSpeed#(1)+newxvalue(0,yAng#,moveDist#(1))
zSpeed#(1)=zSpeed#(1)+newzvalue(0,yAng#,moveDist#(1))
endif
`rückfärts
if backward=1
xSpeed#(1)=xSpeed#(1)+newxvalue(0,yAng#,moveDist#(1)*-1)
zSpeed#(1)=zSpeed#(1)+newzvalue(0,yAng#,moveDist#(1)*-1)
endif
`links
if left=1
yrotate object 1,wrapvalue(yAng#-4)
endif
`rechts
if right=1
yrotate object 1,wrapvalue(yAng#+4)
endif
`---------------------------------
`Physik (1) realistisches anhalten
`---------------------------------
`rechne value aus
xSpeed#(1)=xSpeed#(1)*friction#(1)
zSpeed#(1)=zSpeed#(1)*friction#(1)
`adde gravitation
ySpeed#(1)=ySpeed#(1)+gravity#(0)
`rechne neue pos aus
xPos#=xPos#+xSpeed#(1)
zPos#=zPos#+zSpeed#(1)
yPos#=yPos#-ySpeed#(1)
`col
if xPos#>495 then xPos#=495
if zPos#>495 then zPos#=495
if xPos#<5 then XPos#=5
if zPos#<5 then zPos#=5
`rechne den plheight aus
if yPos#<get ground height(1,xPos#,zPos#)
ySpeed#(1)=ySpeed#(1)+(yPos#-get ground height(1,xPos#,zPos#))
yPos#=get ground height(1,xPos#,zPos#)
`----------------------------------------------
`Physik (2) Realistisch über das terrain fahren
`----------------------------------------------
distVal#=1.2
`rechne die 4eck punkte des hc aus
ang#=yAng# : frontX#=newxvalue(xPos#,ang#,distVal#) : frontZ#=newzvalue(zPos#,ang#,distVal#)
ang#=yAng#+180 : backX#=newxvalue(xPos#,ang#,distVal#) : backZ#=newzvalue(zPos#,ang#,distVal#)
ang#=yAng#+90 : leftX#=newxvalue(xPos#,ang#,distVal#) : leftZ#=newzvalue(zPos#,ang#,distVal#)
ang#=yAng#-90 : rightX#=newxvalue(xPos#,ang#,distVal#) : rightZ#=newzvalue(zPos#,ang#,distVal#)
`rechen die 4eckhöhen punkte aus
frontHeight#=get ground height(1,frontX#,frontZ#)
backHeight#=get ground height(1,backX#,backZ#)
leftHeight#=get ground height(1,leftX#,leftZ#)
rightHeight#=get ground height(1,rightX#,rightZ#)
`rechne matrix tilt aus
xAng#=curveangle((backHeight#-frontHeight#)*30,object angle x(1+10),5)
zAng#=curveangle((leftHeight#-rightHeight#)*30,object angle z(1+10),5)
`update fahrzeug rotationen
rotate object 1+10,xAng#,0,zAng#
`--------------------------------------
`Physik (3) Hügel ohne Gas runtersliden
`--------------------------------------
xMoveDist#=(backHeight#-frontHeight#)/30
zMoveDist#=(leftHeight#-rightHeight#)/30
`justiere vor und rückwärts bewegungen
xSpeed#(1)=xSpeed#(1)+newxvalue(0,yAng#,xMoveDist#)
zSpeed#(1)=zSpeed#(1)+newzvalue(0,yAng#,xMoveDist#)
`justiere links und rechts bewegungen
xSpeed#(1)=xSpeed#(1)+newxvalue(0,yAng#-90,zMoveDist#)
zSpeed#(1)=zSpeed#(1)+newzvalue(0,yAng#-90,zMoveDist#)
endif
`repos pl
position object 1,xPos#,yPos#,zPos#
endfunction
`-------------------
`rechne hotspots aus
`-------------------
function CheckHotspot(1)
`resete derzeitige hotspot
currentHotspot=0
`rechne derzeitige tilt pos des pl aus
tileX=int(object position x(1)/Info(0))+1
tileZ=int(object position z(1)/Info(1))+1
`finde derzeitigen hotspot
For hotSpot=1 to 10
if tileX=FKey(hotSpot,0) and tileZ=FKey(hotSpot,1) then currentHotspot=hotSpot : Exit
Next hotSpot
endfunction currentHotspot
`-----------------------
`artificial intelligence
`-----------------------
function control_player(1)
`get positions
xPos#=object position x(1)
zPos#=object position z(1)
yAng=object angle y(1)
`set movement values
left=0
right=0
forward=1
backward=0
`work out target position
targetXPos=(FKey(hotspot(0),0)*info(0))-(info(0)/2)
targetZPos=(Fkey(hotspot(0),1)*info(1))-(info(1)/2)
`work out angle between payer and target
angle#=atanfull(xPos#-targetXPos,zPos#-targetZPos)-yAng
`work out direction to turn
if angle#<-180
left=1
else
right=1
endif
move_player(1,forward,backward,left,right)
endfunction
`---------------
`pos daten
`---------------
data_player_positions:
`value 1 = x position
`value 2 = z position
`value 3 = y angle
`value 4 = friction
`value 5 = move distance
data 262.5, 212.5, 0, 0.97, 0.065
data 212.5, 262.5, 90, 0.98, 0.55
data 262.5, 312.5, 180, 0.975, 0.06
data 312.5, 262.5, 270, 0.965, 0.08