DarkAI

COMMANDS DEMO


This demo makes use of the entity's manual mode to demonstrate some of the commands used by the automatic mode to control entities, allowing you to create custom behaviours that are not covered by the automatic mode's stance mode and command set. This involves setting the entity destination and look at point depending on the information an entity has about its surroundings, such as recently seen targets or heard sounds.

The demo itself allows you to position a marker object (magenta) and apply various commands to an enemy entity that use this marker for different purposes, like looking or moving towards it. A stationary friendly entity is provided to serve as a target when the enemy gets within sight, including a couple of obstacles to show path finding still working in manual mode and blocking line of sight. This demo does not include any form of attack as it focuses on the manual mode commands.

The first loop sets up the two entities.

for i = 2 to 3

make object i,1,0
position object i,(i*2 - 5) * 30,2.5,0

if ( i=2 )

AI Add Enemy i
color object i,rgb(255,0,0)

else

AI Add Friendly i
color object i,rgb(0,255,0)

endif

AI Set Entity Speed i,10.0
AI Set Entity View Arc i,90,170
AI Set Entity View Range i,50
AI Set Entity Control i,0

next i

Entity 2 becomes the enemy and 3 becomes the friendly, both have the same view angle and range set and both use the Set Control command to set them to manual mode. The friendly entity is set to manual mode to prevent it moving on its own which helps to keep the scene a little cleaner.

The main loop sets the marker object under the mouse when clicked and provides 10 commands that can be given by the user.

AI Entity Go To Position 2, x#, z#

This command tells the entity to move to the marker's position avoiding any obstacles along the way. If the marker is inside an obstacle the entity will move to the closest point outside the obstacle. If the destination is completely blocked by obstacles (the destination is valid but unreachable) the entity will not move. This is the standard method of moving entities around.

AI Entity Stop 2

This command stops the entity moving by setting its destination to its current location no matter what it is currently doing.

AI Entity Look At Position 2, x#, z#

This command tells the entity to look at the marker's position and sets the entity as having a look at point. An entity with a look at point will always look at it whilst it can see it and is not blocked by obstacles (not including half height obstacles), even when moving away from it. If the entity cannot see its look at point it looks in its direction of travel until the point becomes visible again; being visible does not require the point to be in the entity's view angle just that the entity has a clear line of sight to the point.

AI Entity Look Around 2, 90, 180

This command picks a random angle between 90 and 180 and turns the entity either left or right (random choice) by that angle by setting the look at point. The entity will continue to look at this point when moving.

AI Entity Random Move 2, 10, 20

This command picks a random direction from all possible directions, and a random distance between 10 and 20 for the entity to move. The entity's destination is then set to the point at the end of this direction and distance.

AI Entity Move Close 2, x#, z#, 10

This command moves the entity to within 10 units of the marker's position. If the entity is already within 10 units of the marker it picks a new point within 10 units of the marker to move to.

tx# = AI Get Entity Target X(2)
tz# = AI Get Entity Target Z(2)
AI Entity Look At Position 2, tx#, tz#

This set of commands retrieves the position of the entity's current target and sets the entity to look at it. This point will need to be updated each frame if you want the entity to continue looking at its target. The entity may have more than one target in its list but the first target, and the one for which data is returned, is always the closest visible target in its list.

AI Set Entity Position 2, x#, z#
AI Entity Stop 2


This sets the entity's position directly creating a teleport effect where the entity will jump from its current position to the new position. Since this does not also set the entity's destination Stop should be called to prevent the entity moving back to its original location. An entity's destination is always in effect and an entity doesn't move only because its destination is under its feet. Therefore, if the entity's position is changed its destination should be set also for the entity to remain stationary.


AI Set Entity No Look At Point 2


This removes any look at point the entity currently has and returns it to always looking in its direction of travel. When an entity stops moving it will continue looking in the last direction it was moving.

AI Entity Strafe Target 2

This command requires the entity to have a target in its list, if so it picks a sideways direction relative to the direction of the target and moves to a destination randomly placed at the end of this direction. The direction is chosen internally to be either left or right.

Finally the demo displays some information about some entity parameters that can help in deciding what commands to give the entity.

print "Enemy State: ";AI Get Entity State$(2)
print "Num Targets: ";AI Get Entity Count Targets(2)
print "Moving: ";AI Get Entity Is Moving(2)
print "Turning: ";AI Get Entity IS Turning(2)
print "Can Fire: ";AI Get Entity Can Fire(2)

-
Get State returns a description of the current entity state and is most useful in viewing automatic behaviour, its function here is to display the state as being manual and not under automatic control.
-Count Targets returns the number of targets currently in the entity's target list, but visible and recently seen. Targets will slowly be removed from the list when they are not visible for extended periods of time.
-Get Is Moving returns if the entity is currently attempting to move to a destination, whether it is succeeding or not. An unreachable destination will produce a moving result of true even though the entity may not actually be moving.
-Get Is Turning depends if the entity has a look at point, if so it will calculate if it is looking at the point and return false if it is already within 0.1 degrees, if it does not have a look at point it returns true when moving and false when not moving.
-Get Can Fire returns true when the entity has at least one target, at least one target is within its view angle and range and the target is within its fire arc angle.

AI Update

This moves the entity to its destination and turns it to its look at point in response to any commands that have change these values, and updates the entity's target list by adding any new and removing any old targets.