Hi, I am have trouble with A.I. in my (first)game I have got it to sort of work but it is very buggy. The ideas is that the goblin is meant to come after the knight, this does kind of happen but like i said its very buggy. I also want the goblin to attack the knight when it is close. How do i do this?
Could someone please just check my A.I. code and help me were i have gone wrong
And if someone could help with the attacking problem i would be grateful.
Here is my code
rem set sync rate to 40 and hide the mouse
SYNC RATE 40:HIDE MOUSE
rem make matrix
make matrix 1,500,500,10,10
randomize matrix 1,25
LOAD BITMAP "grassy01.bmp",1
GET IMAGE 1,0,0,128,128
DELETE BITMAP 1
PREPARE MATRIX TEXTURE 1,1,1,1
FOG ON:FOG DISTANCE 300
rem Load 3D object and append walking data to it
LOAD OBJECT "H-Knight-Idle.x",1
SCALE OBJECT 1,750,750,750
APPEND OBJECT "H-Knight-Move.x",1,100
APPEND OBJECT "H-Knight-Attack1.x",1,200
APPEND OBJECT "H-Knight-Die.x",1,300
APPEND OBJECT "H-Knight-Impact.x",1,400
YROTATE OBJECT 1,180 : FIX OBJECT PIVOT 1
rem load goblin and append animation
LOAD OBJECT "idle.x",4
YROTATE OBJECT 4,180
APPEND OBJECT "walk.x",4,100
APPEND OBJECT "punch.x",4,200
APPEND OBJECT "falgetup.x",4,300
SCALE OBJECT 4,75,75,75
rem Loop 3D object animation from 0 to 20 (idle)
LOOP OBJECT 1,0,20 : SET OBJECT SPEED 1,10
rem load sword
LOAD OBJECT "sword5.x",2
scale object 2,1500,1500,1500
zrotate object 2,110
yrotate object 2,140
rotate limb 1,13,0,0,160
glue object to limb 2,1,13
fix object pivot 1
rem load shield
LOAD OBJECT "woodshld.x",3
SCALE OBJECT 3,200,200,200
yrotate object 3,300
zrotate object 3,90
glue object to limb 3,1,18
fix object pivot 1
rem load music and play it.
load music "dungeon.mid",1
loop music 1
rem player start positions
z#=RND(500)
x#=RND(500)
gobz#=RND(500)
gobx#=RND(500)
rem Activate manual syncronization
SYNC ON
rem Begin loop
DO
rem Modify character angle based on left/right keys
stage=0
IF LEFTKEY()=1 THEN a#=a#-8.0
IF RIGHTKEY()=1 THEN a#=a#+8.0
a#=wrapvalue(a#)
rem Modify character position based on up/down keys
IF UPKEY()=1 THEN x#=NEWXVALUE(x#,a#,1.5) : z#=NEWZVALUE(z#,a#,1.5) : stage=1
IF DOWNKEY()=1 THEN x#=NEWXVALUE(x#,a#,-1.5) : z#=NEWZVALUE(z#,a#,-1.5) : stage=1
IF SPACEKEY()=1 and stage=0 then PLAY OBJECT 1,200,250
rem If character action changes
IF stage<>oldstage
IF stage=0
SET OBJECT FRAME 1,0.0
LOOP OBJECT 1,0,20
SET OBJECT SPEED 1,10
ENDIF
IF stage=1
SET OBJECT FRAME 1,105.0
LOOP OBJECT 1,105,125
SET OBJECT SPEED 1,20
ENDIF
oldstage=stage
ENDIF
Rem Store old location
Oldgobx# = gobx#
Oldgobz# = gobz#
Oldgoby# = goby#
Rem Play walking animation
Loop Object 4,100,150
Rem Move monster
Move Object 4,1.5
Rem Get new position
gobx# = Object Position X(3)
gobz# = Object Position Z(3)
goby# = Get Ground Height(1,gobx#,gobz#)
rem Update character position and angle
POSITION OBJECT 1,x#,get ground height(1,x#,z#)+2,z#
YROTATE OBJECT 1,a#
point object 4,x#,y#,z#
rem Position camera off center
POSITION CAMERA x#,y#+50,z#-75
rem Refresh screen
SYNC
rem End loop
LOOP
Thanks
Jozers
EDIT
All media is on either DarkMATTER or DarkBASIC CD's
BTW I'm using DBC
EDIT
It might be better if the goblin just walks around Randomly and when its attacked it fights back. Is there anyway i can make the goblin walk around randomly?
Sorry for the change of idea
Jozers