Here is an interesting bug that makes Dark AI and Dark Physics incompatible. In order to use the physics + the AI, you have to reset the AI position every loop to the actual location of the physics body. Since the AI position is different than the last position, it considers the body to be moving. This is fine if the body is already moving. However, if it is stopped for whatever reason (Stopped, Stopped and Attacking) then it instantly changes the AI Action to Moving. This makes the animation of the model vibrate back and forth from attacking to moving.
Here is the code to demonstrate the problem. No media, only Dark AI is required. Dark Physics is not required to run it, I have reproduced the problem as simply as I possibly could. Every time it repositions the AI it slightly moves the entity to an offset position, similar to what would happen with a physics body.
Observe the output when the AI entities are functioning on their own. You can control the green entity with the arrowkeys. Hold down Spacebar to see the problem. Any time the red entity stops to attack, the action begins to vibrate from moving to stopped.
Sync on
AI Start
AI Set Radius 25
autocam off
position camera 0,500,0
Backdrop on
color backdrop 0
make object box 1,1200,1200,5
xrotate object 1,90
color object 1,rgb(100,100,150)
point camera 0,0,0
makeObjectCapsule(2, 60, 25)
color object 2,rgb(30,255,30)
position object 2, 100,50,100
`set shadow shading on 2
AI Add Player 2
makeObjectCapsule(3, 60, 25)
color object 3,rgb(255,30,30)
position object 3, -100,50,-100
`set shadow shading on 3
AI Add Enemy 3
AI Set Entity Speed 3, 60
AI Set Entity View Range 3, 1000
`AI Set Entity View Arc 3, 180, 180
AI Set Entity Fire Arc 3, 5
`AI Set Entity Hearing Range 3, 1000
AI Set Entity Attack Distance 3, 500
AI SET ENTITY AVOID DISTANCE 3, 100
AI Set Entity Aggressive 3
AI Set Entity Can Roam 3, 1
do
text 10,10,"Dark AI Bug Demo."
text 10,20,"Hold down Spacebar to start manually repositioning red entity."
text 10,40,"Red Entity Action: "+AI Get Entity Action$(3)
text 10,50,"Red Entity Moving: "+str$(AI Get Entity Is Moving (3))
if upkey() then move object 2,.1
if downkey() then move object 2,-.1
if leftkey() then move object left 2,.1
if rightkey() then move object left 2,-.1
if spacekey() then AI Set Entity Position 3, object position x(3)+.02, object position z(3)+.02
AI Update
position object 3, object position x(3),50, object position z(3)
sync
loop
function makeObjectCapsule(obj, h#, r#)
h# = h# - r#
if h#<0 then exitfunction
rem rows must be odd
rows = 11
cols = 16
make object sphere obj,r#,rows,cols
lock vertexdata for limb obj,0,1
for i=0 to get VertexData Vertex Count()
x#=get VertexData Position X(i)
y#=get VertexData Position Y(i)
z#=get VertexData Position Z(i)
if y#>0
set VertexData Position i,x#,y#+h#,z#
else
set VertexData Position i,x#,y#-h#,z#
endif
next i
unlock vertexdata
` calculate collision bounds
make mesh from object 1,obj
delete object obj
make object obj,1,0
delete mesh 1
endfunction
Probably the easiest solution would be to add an overloaded function parameter to the command
AI Set Entity Position to keep the current action from changing. Also, the command
AI Get Entity Is Moving shouldn't return TRUE unless the entity is actually moving. As this command illustrates, it returns TRUE if the position has changed due to the at all due to the
AI Set Entity Position command, even though the actual position of the model has not changed.
Hope this example is clear enough!
Come see the WIP!