Jump to content
Sign in to follow this  
meatball

Thoughts on handling patrolling/pathing of multiple units

Recommended Posts

So, here's the basics of what I'm looking to do. I want to have individual civilian faction AI act randomly, moving about, doing idle animation, etc. in a mission. It is a MP mission, so there may be a _lot_ of AI scattered across the server. This is a MP mission where the players will likely be scattered. Even with AI spawning/caching, there's likely to be a lot of civilians moving around and spawned at the same time. I've tried a bunch of different things, but have run into some challenges:

1) If I spawn multiple AI into one group, there doesn't appear to be any way to force them to behave / move individually. Even if I command them separately, they'll always return into some sort of formation. I also can't assign each AI to it's own group, because with the 144 limit of groups/side, I run out of groups when AI is being spawned all around.

2) I can't seem to figure out a way to make 'playMove' and 'doMove' work well together. I'd like random animations so somethings the unit is walking, sometimes running, etc, but the doMove seems to just force the unit into a default 'walk' move.

3) setDir does not do a smooth turning animation/transition, it just slaps the unit the direction. If I'd like the unit to occasionally switch to a random direction, is there any way to make that a smooth turn?

Anyone have any thoughts on any of these?

To put it all in perspective, let's just say hypothetically, I want a big city to have 150+ AI, all moving about individually, doing different animations including walking, running, standing idle, etc. What would be a good way to handle that?

Edited by Meatball

Share this post


Link to post
Share on other sites

While not exactly the same, here's how I'm achieving a somewhat similar goal:

private ["_grp","_waypointPos","_waypoint","_nearestBuilding","_i"];


_grp = _this select 0;
_waypointPos = [5,5,0];


_grp allowFleeing 0;
while {surfaceIsWater _waypointPos} do {
_waypointPos = [ZonePos,ZoneRad,random(360)] call BIS_fnc_relPos;
};


_waypoint = _grp addWaypoint [_waypointPos,0];
_waypoint setWaypointType "MOVE";
_waypoint setWaypointStatements ["true","[group this] call spike_fnc_newWaypoint;"];
_waypoint setWaypointBehaviour "COMBAT";
_waypoint setWaypointCombatMode "RED";
_waypoint setWaypointCompletionRadius 30;
_waypoint setWaypointVisible false;


_nearestBuilding = nearestBuilding _waypointPos;
if (([_nearestBuilding,_waypointPos] call BIS_fnc_distance2Dsqr) < 225) then {
   _i = 0;
   while { ((_nearestBuilding buildingPos _i) select 0) != 0 } do {
       _i = _i + 1;
   };


   if (_i > 0) then {
       _waypoint waypointAttachObject _nearestBuilding;
       _waypoint setWaypointHousePosition floor(random _i);
       _waypoint setWaypointCompletionRadius 0;
   };
};

As you can see this is a function which I then set to be called once the next waypoint is completed. I'm personally using it for a very specific hostile situation within a very specific area, I just assign it to each of my AI groups (don't worry, I did read you post). You can see that I'm picking a random position within my area which doesn't lie in water. After that I'm setting a new waypoint to that position and changing the waypoint parameters. If the position is close enough to a building I'm setting the waypoint position to a random position in that building (if it has any).

The benefit to using waypoints like this is that I don't have any loops, the function is simply run at the rate which the AI completes the waypoints in. I'm not sure if this is of much help since you inquire specifically about doMove and playMove (presumably due to the mentioned group limit), but perhaps it'll spur an idea or something. If not then perhaps it'll be a good compromise.

I feel like a lot of workarounds could be avoided if that group limit at least wasn't so low. Do we even know why it's 144 and why BI haven't felt a need to change it?

Share this post


Link to post
Share on other sites

I really like the idea you have of using a function to set waypoint and then recalling that function to set the next one when the units reach the first waypoint. Definitely seems like it'll ease up on resources needed for the AI as opposed to some sort of loop. Doesn't fully help me though since I need the AI to act individually and not as a single group and I'll probably have over the 144 limit. Not sure why they haven't changed it, but I can kinda see why since if you have 2-3 per group with 144 groups you can pretty quickly overload a machine.

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
Sign in to follow this  

×