Hey was wondering if anyone got dark ai to work well with sparkys collision. I've been trying to get it to work, but I either get sticky collisions (no sliding) or very jittery movement.
Here is the code I have so far, it basically follows the instructions given on the dark ai help file. I'm still rather annoyed it doesn't come with an example.
autocam off
ai start
position camera 0,200,100
point camera 0,0,0
load object "t1.x",1
sc_setupObject 1,1,0
AI Add Obstacle From Level 1, 8, 1, 1
ai complete obstacles
global radius# = 8.0
make object sphere 10,16
color object 10,rgb(100,50,50)
position object 10,50,8,50
ai add friendly 10,0
AI Set Entity Control 10,0
ai set entity position 10,50,50
sc_setupObject 10,0,1
set shadow shading on 10, -1, 500, 1
make object sphere 11,8
color object 11,rgb(50,50,100)
position object 11,-32,8,-64
make light 1
position light 1,0,200,100
set light range 1,512
color light 1,50,25,50
position light 0,0,50,25
ai debug show paths 16
ai debug show waypoints 0,16
v = 10
sync on
sync rate 60
do
// move the destination
if rightkey() = 1
move object left 11,10
endif
if leftkey() = 1
move object right 11,10
endif
if downkey() = 1
move object 11,10
endif
if upkey() = 1
move object 11,-10
endif
old_aix# = ai get entity x(10)
old_aiz# = ai get entity z(10)
ai_a# = ai get entity angle y(10)
ai update
ai entity go to position 10,object position x(11),object position z(11)
oldx1# = object position x(v)
oldy1# = object position y(v)
oldz1# = object position z(v)
aix# = ai get entity x(10)
aiz# = ai get entity z(10)
x# = object position x(10)
z# = object position z(10)
follow(10,x#,z#,aix#,aiz#,8,10)
x# = object position x(v)
y# = object position y(v)
z# = object position z(v)
rem player only collides with group 1 (level) objs and moves freely through others
collide = sc_SphereSlideGroup(1,oldx1#,oldy1#,oldz1#,x#,y#,z#,radius#,0)
if collide>0
rem if hit, reposition player, halt movement vector
x# = sc_getCollisionSlideX()
y# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
rem re-position the player
position object v,x#,y#,z#
`if distance(ai get entity x(v),ai get entity z(v),x#,z#)>8.0
AI Set Entity Position v,x#,z#
` endif
endif
sc_updateObject 10
sync
loop
Function Follow(objout,x#,z#,x1#,z1#,y#,spd#)
`Calculate the X and Y distance between the Two
DistX#=x#-x1#
DistZ#=z#-z1#
`Calculate the angle the enemy has to face to point to the player
ang#=(ATANFULL(DistZ#,DistX#))
`Calculate the distance to move the enemy
MoveX# = Cos(ang#) * spd#
MoveZ# = Sin(ang#) * spd#
if distance(x1#,z1#,x#,z#)>8.0
`Move the enemy towards the player
x1# = x1# + MoveX#
z1# = z1# + MoveZ#
endif
position object objout,x1#,y#,z1#
`yrotate object objout,ang#
EndFunction
function distance(x1 as float,z1 as float,x2 as float,z2 as float)
dist#=sqrt((x1-x2)^2+(z1-z2)^2)
endfunction dist#
cheers
edit - attached required media