I'm trying to use DP and DAI together. To achieve this, I used Sparky's collision to create my own character controller, letting that dictate where the enemy model goes. I'm having an issue where, although it follows the patrol path I assigned it, and
turns in random directions while patrolling. How do I fix this?
Here's the main program loop:
//Main Program Loop
Do
AI Update
set cursor 0,0
//Update Timer-Based Movement
TBM_update()
Dn=Duration*60
MoveOldTime# = NewTime#` DBC/DBP
AI Set Entity Speed SonarakObj,25.0*Dn
// apply gravity, and user changes to movement
vx#(ControlBox) = 0
vz#(ControlBox) = 0
// handle debugging output
gosub AIDebug
//Update Camera
camera(SessetaObj)
`SonarakObj AI coordinates.
aiX# = AI Get Entity X ( SonarakObj )
aiZ# = AI Get Entity Z ( SonarakObj )
aiAngY# = AI Get Entity Angle Y(SonarakObj)
DisplayInfo(SessetaObj, SonarakObj, ControlBox)
//Configure and regulate the XYZ positions of the player
//and the other objects
//gosub ObjectPositioning
`Store the AI Entity's old position on the xyz axis
OX#(ControlBox) = OBJECT POSITION X(ControlBox)
OY#(ControlBox) = OBJECT POSITION Y(ControlBox)
OZ#(ControlBox) = OBJECT POSITION Z(ControlBox)
//Player movement
PC_Move(SessetaObj)
// if player is jumping or falling then apply 'normal' gravity
// if not attempt to keep the player stuck to the floor
if vy#(ControlBox)=0 and jumpwait(ControlBox)=0
vy#(ControlBox) = vy#(ControlBox) + 10*_GRAVITY
else
vy#(ControlBox) = vy#(ControlBox) + _GRAVITY
endif
//Setup EZRotate for Sonarak
EZro_SetEuler object angle x(ControlBox), object angle y(ControlBox),object angle z(ControlBox)
EZro_SetPos OX#(ControlBox), OY#(ControlBox), OZ#(ControlBox)
//If the AI entity is moving, perform these tasks
if AI Get Entity Is Moving ( SonarakObj ) = 1
//EZRotate commands
EZro_TurnTo aiX#, OY#(ControlBox), aiZ#, aiAngY#
EZro_FindEuler
yrotate object ControlBox, EZro_GetEulerY()
//Walking animation
EWalk_anim(SonarakObj, 11, 170)
//Check distance and push it the entire distance between
//the two points
if DistCheck2D(OX#(ControlBox),OZ#(ControlBox),aiX#,aiZ#) < h#
vx#(ControlBox) = vx#(ControlBox) + sin(aiAngY#)
vz#(ControlBox) = vz#(ControlBox) + cos(aiAngY#)
else
AI Set Entity Position SonarakObj, OX#(ControlBox), OZ#(ControlBox)
endif
//rotate it back to the AI Y-angle, as reported by Dark AI
yrotate object ControlBox, aiAngY#
else
//Frame 0 - idle state
AnimFrame#(SonarakObj) = 0
set object frame SonarakObj, AnimFrame#(SonarakObj)
endif
`Store the AI Entity's new position on the xyz axis, after they've moved.
X#(ControlBox) = OX#(ControlBox) + vx#(ControlBox)
Y#(ControlBox) = OY#(ControlBox) + vy#(ControlBox)
Z#(ControlBox) = OZ#(ControlBox) + vz#(ControlBox)
oldX# = OX#(ControlBox) : oldY# = OY#(ControlBox) : oldZ# = OZ#(ControlBox)
newX# = X#(ControlBox) : newY# = Y#(ControlBox) : newZ# = Z#(ControlBox)
//Sparky's Collision for Sonarak
SlidingCollision(oldX#,oldY#,oldZ#,newX#,newY#,newZ#,10,ControlBox,LandObj)
//Position the Sonarak model to the Control Box position
position object SonarakObj, X#(ControlBox), OBJECT POSITION Y(ControlBox),Z#(ControlBox)
yrotate object SonarakObj, object angle y(ControlBox)
//Update Dark Physics
phy update
sync
Loop
Currently working on - Enemy AI using Dark A.I. I probably should've looked at the reviews in the Dark Physics and Dark A.I. forum first.