Having AI run after and kill you.

I have been working on a Zombie-like system inside arma 3 and want to have the AI chase after my player and kill me. This should be very simple to do, however I failed to find a good way of doing it with the built-in AI scripting commands. I did a bit of research and came up with this segment of code.
Now the issue with AI in arma is that they don’t like to run. There is also no easy way to have them go directly towards a targeted unit. I had to come up with a system that was not too heavy on performance but also made them move quite smoothly. I started with a simple VR mission. I added myself and an AI unit.
I then added “AI = this” into the ai’s init field.
Now, back to the script.  Someone had posted on ArmAHolic with the event handler you see at the top of the code. What this does is change the standard movement animation into the running animation on the AI unit. I then create a thread that waits for the AI to become within a certain distance of the player and kill him. I use setDir to make it look as if they turned to face me. The while loop at the bottom is the bulk of the code however. This creates an area around the player that acts like a trigger. Once the player leaves that area the AI will recalculate the direction it should head in. This area shrinks as the AI moves closer to the player and thereby causes the AI to turn towards the player as it draws nearer. This creates a similar effect to the zombies in DayZ Mod from ArmA 2.

Just a neat tidbit of code. Sorry for being inactive, just trying to look for interesting topics to post on.

Liked it? Take a second to support Lystic on Patreon!
About Lystic 19 Articles
ArmA Scripter. Former cheater. Always have security in mind.