New component for Alice game AI
So far we have made it possible for the AI to retreat upon sensing how many of them are alive. But in real life situations, retreats are also made depending on how much damage something has taken. So how does one create an AI that retreats if it is too damaged? There’s a few solutions to this. One solution is to just have an if fuction where if the the opacity of the unit is .5, then add one to the health parameter. This could work, for in the health system you have a function where when it is “hit” or when the health variable increases, it sets it’s opactity to .5. There is, however, a more reliable solution. As you know, the world can have variables (you create them in the properties tab when you have selected world from the objects tile) but you can do the same for objects. You can create a variable for objects through the object’s properties. The component would look like this:
To add to AI:
If health >= number
world.retreat who=who
else do nothing
Note: number is defined by you
And you would add this to the detection method as well. The detection method would now look like this:
world.enemydetection
parameters who(object) gun(object) health(number)
loop infinite times
for all squad1 together
if who is within 10 meters of enemy
item_from_squad1 turn to face enemy
item_from_squad1 move foward number meters
world.enemyAI who=who gun=gun health=health
else
do nothing
if health>=number
world.retreat who=who
else
do nothing
note: number is defined by you
And it would look like this in the events area:
when world starts do world.enemy detection who=tank gun=tank.turret.barrel.longgun health=tank.health
This way. the AI can now retreat upon sensing it’s own damage. This is also an easier method, and the object variable can also be used for other things besides just AI.
(Note: this component has seen some bugs in testing and is still being redesigned, so there’s no gurantee that this component will work)