Jump to content
JB47394

Forcing AI to follow waypoints

Recommended Posts

I have always found the AI to be infuriating in their preference to engage enemies versus going where they're told.  They just don't prioritize as I'd like them to. If you can't ever seem to get the AI to go where you need them, try the following.

_group setSpeedMode "full";
{
    private _soldier = _x;
    _soldier setUnitPos "up";
    { _soldier disableAI _x } foreach ["cover", "suppression", "target", "autotarget", "autocombat"];
} foreach units _group;

This is the most aggressive form of this technique.  It says "don't worry about getting shot, and don't engage anyone, just move".  There may well be more refined versions of this.  Note that this makes sure they run to their waypoint.  They will ignore everything and just run.  If you try this in the editor, you'll see them running right past enemies who will turn and shoot them dead.  It's "careless" at a run.

The more advanced use of this has the AI reacting to serious threats such that they revert to their normal behavior - which I certainly want.  That involves the use of event handlers to turn those AI capabilities back.

Some of the event handlers of interest are:

1. FiredNear - when there is gunfire close to the soldier

2. Hit - when the soldier is wounded.  This can be filtered to determine if the damage comes from friend, foe or environment.

3. Killed - when the soldier is killed.  Again, filtering can be used.

If you want your AI to abandon their waypoint fairly easily, use FiredNear or Hit.  Hit can be tuned for specific levels of damage, right down to specific body parts.  If you want the group to be pretty hardcore about reaching their waypoint, used Killed.  If you want them to be mindless zealots, don't enable the AI capabilities until they reach the waypoint via setWaypointStatements .  This can also be handy for getting soldiers to flee when you want them to - because they prioritize their waypoints above all else.

This is the code I use to get a group of infantry moving until one of them is killed by enemy fire.

GroupAdvance =
{
	params ["_group"];

	private _soldier = objNull;
	private _handler = -1;

	_group setSpeedMode "full";
	{
		_soldier = _x;

		{ _soldier disableAI _x } foreach ["cover", "suppression", "target", "autotarget", "autocombat"];
		_soldier setUnitPos "up";
		_handler = _soldier addEventHandler ["Killed",
			{
				params ["_unit", "_killer", "_instigator"];

				if (not isNull _instigator && { side group _instigator != side group _unit }) then { [group _unit] call GroupEngage };
			}];
		_soldier setVariable ["AdvanceHandler", _handler];
	} foreach units _group;
};

GroupEngage =
{
	params ["_group"];

	private _soldier = objNull;

	{
		_soldier = _x;
		{ _soldier enableAI _x } foreach ["cover", "suppression", "target", "autotarget", "autocombat"];
		_soldier removeEventHandler ["Killed", _soldier getVariable ["AdvanceHandler", -1]];
	} foreach units _group;
};

For novices, you would use the following on a group that you have a reference to in the variable "_group";

[_group] call GroupAdvance;

Once you do that, that group will follow their waypoints until one of their members is shot dead.  I leave it to the reader to figure out how to have them react to FiredNear, Hit or any other event.

  • Like 1

Share this post


Link to post
Share on other sites

Another good and simple INIT string would be 

Quote

_group1 enableAttack false

 

It works really well for VICS that are on WPs whom you want to keep moving OR stay on position,for example on a WP thats counting down.

They will still attack enemies,but will not move position or leave their route to do so.

  • Like 2

Share this post


Link to post
Share on other sites

Thanks.  That pointer is much appreciated.  I suspect that I can use it to solve a host of problems with my armed transports.  Do you have an experience with that command as it applies to infantry?

Share this post


Link to post
Share on other sites
2 hours ago, JB47394 said:

Thanks.  That pointer is much appreciated.  I suspect that I can use it to solve a host of problems with my armed transports.  Do you have an experience with that command as it applies to infantry?

On the infantry group level this should stop the group leader issuing individual orders to his team members to engage targets.

 

So it should stop units breaking formation to target an enemy,the opposite and possibly over written by  would be

Quote

setCombatMode RED;

Therefore you may use it on a group that are on stealth and hold fire,trying to move from one point to another and it may speed up the groups movement.

Using it on armed transports is quite useful.I always by default have my vehicles on friendly AI side utilize enableAttack false,unless i need a vehicle to S&D in an area.Try it on a armed helo carrying troops,such as the CSAT AH,the gunner should shoot his cannon at spotted targets(pilot if leader, wont issue attack order,but will share info on known targets)and pilot should be unafected and move to WPs ie dropping off troops...

Share this post


Link to post
Share on other sites
On 10/9/2018 at 12:39 AM, redarmy said:

It works really well for VICS that are on WPs whom you want to keep moving OR stay on position,for example on a WP thats counting down.

They will still attack enemies,but will not move position or leave their route to do so.

Unfortunately, all my tests suggest that this doesn't accomplish what I'm after.  In truth, it doesn't seem to accomplish anything.

My test involved creating a Marid and sending it down a road past various enemies.  For example, a couple enemy Hunter HMGs.  If I start the Marid with behavior "aware", then it will drive past the Hunters, the Hunters will shoot at the Marid, and it will turn aside from its waypoint to engage the Hunters.  If I start the Marid with behavior "combat", then it will spot the Hunters, stop and engage.  Tested both in the editor and on a dedicated server.

What I'm after is to have a Marid transport drive from point A to point B, drop of troops and leave.  If it happens to see enemies, it shoots at them, but not at the cost of its primary mission.  So I need movement to be the priority, not shooting.

I've tried dozens of variations on directing a three-man crew such that they prioritize movement and I've been unable to get a Marid to do it.  I've tried changing the organization of the groups for the crew members (to the point of putting the driver into a group led by an AI that's nowhere near the fight), disabling various aspects of AI, fiddling with the various modes available, etc.  At all times, if the gunner is capable of engaging an enemy, the vehicle will ignore the waypoint.

The solution I've been working with for the last year or so is a time-based monitor.  The Marid is expected to keep a schedule.  So long as it doesn't fall behind, it can shoot.  If it does fall behind,, it is forced into a movement-only mode and that usually gets the vehicle back on track.  If it gets back on schedule, it is left free to shoot again.  It's hardly ideal, because it requires a spawned monitor and other complexity, but at least the Marids both shoot and move, if not at the same time.

The Advance/Engage system for infantry seems to be working well but, as with my Marid solution, it's a "move or shoot" setup.  At least it's event based.

If anyone has a working system that allows simultaneous move and shoot that works with a Marid, I'd love to hear about it.

Share this post


Link to post
Share on other sites

One of the best result is simple:

(driver this) setbehaviour "safe"; (driver this) disableAI "autoCombat";   in init field of the marid.

 

Share this post


Link to post
Share on other sites
On 10/20/2018 at 11:58 AM, pierremgi said:

One of the best result is simple:

(driver this) setbehaviour "safe"; (driver this) disableAI "autoCombat";   in init field of the marid.

Yes, I tried that very early on.  Unfortunately, safe crews turn out and safe soldiers walk.  The techniques I've used above keep the crews buttoned up and the infantry moving at whatever pace I choose.

Share this post


Link to post
Share on other sites

Hello, How do you make them follow roads using waypoints or like other things like after you get to the waypoint you go to the next waypoint? I need a answer because im making a convoy scenario. I would appreciate if anyone would answer/ say a solution.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×