Unknown
From DarkAI
Compatibility With A Physics System
The
main issue with combining DarkAI with a physics system, such as
DarkPhysics, is that physics will also want to control the DarkBasic
objects representing your entities to stop them moving through each
other. If you link the objects with the AI system with the physics
system trying to move them conflicts may arise between which position
the object should be moved to. The solution to this is to give
control of the object over to physics as normal and to not link the
object to the AI system, instead using the Set Position and Get X/Z
commands to change and retrieve the entities' positions.
If
the physics system can detect when an object is re-positioned and
update its internal values then the two systems should work together
as long as AI Update is called before updating physics. This avoids
the possibility that after physics has prevented collisions the AI
moves the entity into a new collision. If this is not the case then
you can remove the AI system from controlling the entity and use the
physics system to position the entity where the AI wants it to go.
When not linked to an object DarkAI will use internal values
that represent where it thinks the entity should be when AI Update
is called, use AI Get Entity X and AI Get Entity Z
commands to get these values. You should then use methods provided by
the physics system to move the DarkBasic object to this position, for
example using forces, velocities or positions whichever the physics
system prefers, and let the physics system move the DarkBasic object.
Then update the physics system so that it positions the DarkBasic
object for you and adjusts for collisions, etc, automatically. Then
get the new position of the object using the normal DarkBasic
commands Object Position X and Object Position Z and
use the AI Set Entity position command to set the new internal
position for DarkAI to work with. This new value will then be used by
the AI system in the next AI Update to work out where it wants
the entity to move to, it stores these new values internally and the
cycle repeats. It is recommended you always update the AI before you
update the physics in your loop.
You can use AI Set Entity
Collide to tell an entity when it is blocked by something it
doesn't know exists (a physics object that is not an obstacle in the
AI system) which the AI would constantly try to move through and
physics would keep stopping it. This tells the entity to move
sideways for a bit.