Made a node-handler. Its also being used in the bluespace project.
set display mode 800,600,32
sync on:sync rate 100
backdrop on
color backdrop 0
make matrix 1,50,50,25,25
`position matrix 1,-25,0,-25
ghost matrix on 1,2
` ## DEFINE TYPES ## `
TYPE PATH_NODE
OBJ_ID AS INTEGER
POS_X AS FLOAT
POS_Y AS FLOAT
POS_Z AS FLOAT
MAX_ND AS INTEGER
T_TIME# AS FLOAT
V# AS FLOAT
ENDTYPE
TYPE AI_OBJECT
OBJ_ID AS INTEGER
PATH_ID AS INTEGER
POS_X AS FLOAT
POS_Y AS FLOAT
POS_Z AS FLOAT
ROT_X AS FLOAT
ROT_Y AS FLOAT
ROT_Z AS FLOAT
NODE AS INTEGER
SPEED AS INTEGER
START_NODE AS INTEGER
END_NODE AS INTEGER
LOOP_NODE AS INTEGER
ROT_ACT AS INTEGER
NEW_AX# AS FLOAT
NEW_AY# AS FLOAT
NEW_AZ# AS FLOAT
FOLLOW_OBJ AS INTEGER
ENDTYPE
DIM PATHNODE(500,25) AS PATH_NODE
DIM AIOBJECT(500) AS AI_OBJECT
DIM NODECOUNT(500)
GLOBAL OFFSET AS INTEGER : OFFSET = 24305
GLOBAL OFFSET_AI AS INTEGER : OFFSET_AI = 24805
GLOBAL NODE_ACC# AS FLOAT : NODE_ACC# = 10
` ## CREATE NODES ## ` (PARAMS: NODE-ID , PATH_ID , X,Y,Z)
CREATE_NODE(1,1,7*3,5,2*3)
CREATE_NODE(2,1,6*3,10,2*3)
CREATE_NODE(3,1,5*3,15,3*3)
CREATE_NODE(4,1,4*3,15,3*3)
CREATE_NODE(5,1,4*3,15,4*3)
CREATE_NODE(6,1,4*3,15,5*3)
CREATE_NODE(7,1,4*3,15,6*3)
CREATE_NODE(8,1,4*3,15,7*3)
CREATE_NODE(9,1,5*3,10,7*3)
CREATE_NODE(10,1,6*3,10,8*3)
CREATE_NODE(11,1,7*3,10,8*3)
CREATE_NODE(12,1,8*3,10,8*3)
CREATE_NODE(13,1,9*3,5,8*3)
CREATE_NODE(14,1,9*3,5,7*3)
CREATE_NODE(15,1,10*3,5,6*3)
CREATE_NODE(16,1,10*3,10,5*3)
CREATE_NODE(17,1,10*3,10,4*3)
CREATE_NODE(18,1,10*3,5,3*3)
CREATE_NODE(19,1,9*3,5,3*3)
CREATE_NODE(20,1,8*3,5,2*3)
make object box 10,5,5,5
ghost object on 10
` ## CREATE OBJECT ## ` (PARAMS: OBJ_ID , PATH_ID, START_NODE, END_NODE, SMOOTH, LOOP(BOOLEAN))
CREATE_AI_OBJECT(1,1,1,20,100,1)
do
set cursor 10,10:print "AI-PathFinding MODULE for BlueSpace Project"
set cursor 10,20:print "-------------------------------------------"
set cursor 10,40:print "Current NODE (path=1): ";AIOBJECT(1).NODE
`POSITION CAMERA -40,20,-40
`POINT CAMERA AIOBJECT(1).POS_X,AIOBJECT(1).POS_Y,AIOBJECT(1).POS_Z
PLAY_OBJECT_ON_NODE(1,1,10)
`PLAY_OBJECT_ON_NODE(2,2)
`PLAY_OBJECT_ON_NODE(3,3)
SET CAMERA TO FOLLOW OBJECT POSITION X(10),OBJECT POSITION Y(10),OBJECT POSITION Z(10),OBJECT ANGLE Y(10),15,5,50,1
` POSITION CAMERA -30,20,-30
` POINT CAMERA 0,0,0
sync
loop
FUNCTION SET_MAXNODES(A,B)
NODECOUNT(A) = B
ENDFUNCTION
FUNCTION PLAY_OBJECT_ON_NODE(OBJ,PATH_ID,FOLLOW_OBJ)
OLDCX# = CAMERA POSITION X()
OLDCY# = CAMERA POSITION Y()
OLDCZ# = CAMERA POSITION Z()
OLDAX# = CAMERA ANGLE X()
OLDAY# = CAMERA ANGLE Y()
OLDAZ# = CAMERA ANGLE Z()
X# = OBJECT POSITION X(OBJ+OFFSET_AI)
Y# = OBJECT POSITION Y(OBJ+OFFSET_AI)
Z# = OBJECT POSITION Z(OBJ+OFFSET_AI)
curr_node_x# = OBJECT POSITION X(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID)
curr_node_y# = OBJECT POSITION Y(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID)
curr_node_z# = OBJECT POSITION Z(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID)
if OBJECT EXIST(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID)=1
IF AIOBJECT(OBJ).NODE = AIOBJECT(OBJ).END_NODE
IF AIOBJECT(OBJ).LOOP_NODE = 0
next_node_x# = OBJECT POSITION X(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID)
next_node_y# = OBJECT POSITION y(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID)
next_node_z# = OBJECT POSITION z(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID)
else
next_node_x# = OBJECT POSITION X(PATHNODE(AIOBJECT(OBJ).START_NODE,PATH_ID).OBJ_ID)
next_node_y# = OBJECT POSITION y(PATHNODE(AIOBJECT(OBJ).START_NODE,PATH_ID).OBJ_ID)
next_node_z# = OBJECT POSITION z(PATHNODE(AIOBJECT(OBJ).START_NODE,PATH_ID).OBJ_ID)
endif
else
next_node_x# = OBJECT POSITION X(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID+1)
next_node_y# = OBJECT POSITION y(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID+1)
next_node_z# = OBJECT POSITION z(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID+1)
endif
endif
IF OBJECT COLLISION(OBJ+OFFSET_AI,(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID))=1
AIOBJECT(OBJ).NODE = AIOBJECT(OBJ).NODE + 1
IF AIOBJECT(OBJ).NODE = AIOBJECT(OBJ).END_NODE+1
IF AIOBJECT(OBJ).LOOP_NODE = 0
AIOBJECT(OBJ).NODE = AIOBJECT(OBJ).END_NODE
ELSE
AIOBJECT(OBJ).NODE = AIOBJECT(OBJ).START_NODE
ENDIF
ENDIF
ENDIF
nspeed# = 4.0
node_dist# = C_DIST(curr_node_x#,curr_node_y#,curr_node_z#,next_node_x#,next_node_y#,next_node_z#)
node_speed# = node_dist# / nspeed#
`point object OBJ+OFFSET_AI,next_node_x#,next_node_y#,next_node_z#
`move object OBJ+OFFSET_AI,node_speed#
POSITION CAMERA X#,Y#,Z#
SET CAMERA TO FOLLOW OBJECT POSITION X(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID),OBJECT POSITION Y(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID),OBJECT POSITION Z(PATHNODE(AIOBJECT(OBJ).NODE,PATH_ID).OBJ_ID),0,0,0,AIOBJECT(OBJ).SPEED,1
POSITION OBJECT OBJ+OFFSET_AI,CAMERA POSITION X(),CAMERA POSITION Y(),CAMERA POSITION Z()
ROTATE OBJECT OBJ+OFFSET_AI,CAMERA ANGLE X(),CAMERA ANGLE Y(),CAMERA ANGLE Z()
set cursor 10,70:print "Current Node position: ";curr_node_x#;" , ";curr_node_y#;" , ";curr_node_z#;" , "
set cursor 10,85:print "Next Node position: ";next_node_x#;" , ";next_node_y#;" , ";next_node_z#;" , "
set cursor 10,55:print "Current distance between nodes: ";node_dist#
set cursor 10,100:print "AI.OBJECT speed: ";node_speed#
position camera object position x(FOLLOW_OBJ),object position y(FOLLOW_OBJ),object position z(FOLLOW_OBJ)
set camera to follow object position x(AIOBJECT(OBJ).OBJ_ID),object position y(AIOBJECT(OBJ).OBJ_ID),object position z(AIOBJECT(OBJ).OBJ_ID),camera angle y(),0,0,AIOBJECT(OBJ).SPEED*2,1
position object FOLLOW_OBJ,camera position x(),camera position y(),camera position z()
rotate object FOLLOW_OBJ,camera angle x(),camera angle y(),camera angle z()
POSITION CAMERA OLDCX#,OLDCY#,OLDCZ#
ROTATE CAMERA OLDAX#,OLDAY#,OLDAZ#
ENDFUNCTION
FUNCTION CREATE_AI_OBJECT(OBJ,PATH_ID,START_NODE,END_NODE,SPEED,LP)
MAKE OBJECT BOX OBJ+OFFSET_AI,1,1,1
`hide object OBJ+OFFSET_AI
NX# = OBJECT POSITION X(PATHNODE(START_NODE,PATH_ID).OBJ_ID)
NY# = OBJECT POSITION Y(PATHNODE(START_NODE,PATH_ID).OBJ_ID)
NZ# = OBJECT POSITION Z(PATHNODE(START_NODE,PATH_ID).OBJ_ID)
POSITION OBJECT OBJ+OFFSET_AI,NX#,NY#,NZ#
AIOBJECT(OBJ).OBJ_ID = OBJ+OFFSET_AI
AIOBJECT(OBJ).PATH_ID = PATH_ID
AIOBJECT(OBJ).POS_X = NX#
AIOBJECT(OBJ).POS_Y = NY#
AIOBJECT(OBJ).POS_Z = NZ#
AIOBJECT(OBJ).NODE = START_NODE
AIOBJECT(OBJ).SPEED = SPEED
AIOBJECT(OBJ).START_NODE = START_NODE
AIOBJECT(OBJ).END_NODE = END_NODE
AIOBJECT(OBJ).LOOP_NODE = LP
ENDFUNCTION
FUNCTION CREATE_NODE(OBJ,PATH_ID,POSX as float,POSY as float,POSZ as float)
MAKE OBJECT SPHERE OBJ+OFFSET,0.5
POSITION OBJECT OBJ+OFFSET,POSX,POSY,POSZ
`HIDE OBJECT OBJ+OFFSET
PATHNODE(OBJ,PATH_ID).OBJ_ID = OBJ+OFFSET
PATHNODE(OBJ,PATH_ID).POS_X = POSX
PATHNODE(OBJ,PATH_ID).POS_Y = POSY
PATHNODE(OBJ,PATH_ID).POS_Z = POSZ
PATHNODE(OBJ,PATH_ID).MAX_ND = MAXNODES
COLOR OBJECT OBJ+OFFSET,RGB(100,255,100)
ENDFUNCTION
function C_DIST(x1,y1,z1,x2,y2,z2)
Distance#=SQRT(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))+((z1-z2)*(z1-z2)))
endfunction Distance#
It basicly gives you the possibility to create nodes, and a node_path follower.
the follow_object is the object thats following the node (doh!)
Kevil fixed the object rotation for the biggest part