Jump to content
Sign in to follow this  
krytosss

How to Make Civilians Walk On Roads? -- For a Machinima

Recommended Posts

I am trying to get my civilians to run and/or walk down the middle of the road. They will not do it and I believe it's because the roadways are designed for civilians to avoid walking on them and let vehicles drive by instead.

I've tried every combination in the waypoint system I can think of (careless, safe, never fire, full, normal, etc.), and still my civilians will always default to run along the side of the road.

The only solution I can come up with is to force dozens of very small waypoints to keep them on the road.

Is there some sort of behavior I need to turn off? Disable roads pathfinding or something? Thank you in advance! :)

Share this post


Link to post
Share on other sites

Unfortunately for you ArmA 2 AI are pretty much hard coded. There are a few AI mods out there that alter their behaviors but these were made by very talented developers. I'm not sure if ASR has some sort of function like this. If I would expect anything to have this it would either be that or UPS/UPSMON.

Share this post


Link to post
Share on other sites

Hmm, using safe/careless never seemed to work for me for keeping people on roads. I was in the same boat as krytosss.

Share this post


Link to post
Share on other sites

That function here comes from ACR. I guess it's specifically designed for cinematic stuff.

//--------------------------------------------------------------------------------------------------
// RUN ONLY ONCE SAFE-CHECK
//--------------------------------------------------------------------------------------------------
if !(isNil{BIS_FncInitialized_ScriptedMove}) then {
if (BIS_FncInitialized_ScriptedMove) exitwith {};
};
BIS_FncInitialized_ScriptedMove = true;


BIS_scriptedMoveEnabled = TRUE;

//[_unit:object, _positions:array, _execCode:code] spawn BIS_movingProc;
BIS_movingProc = {

_guy = _this select 0;
_wps = _this select 1;
_walkAnim = "AmovPercMrunSrasWrflDf";
_animLength = 7.07243;
_code = {};
if (count _this > 2) then {_code = _this select 2};

_guy disableAI "MOVE";

//calculate total distance to walk and how many times we need to play the walk animation
_dist = _guy distance (_wps select 0);
_i = 1;
while {_i < count _wps} do {
	_dist = _dist + ((_wps select (_i - 1)) distance (_wps select _i));
	_i = _i + 1
};
_animLoops = ceil (_dist / _animLength);
textLogFormat ["SCRIPTED WALK: %1 will walk %2 meters using %3 animations '%4'.", name _guy, _dist, _animLoops, _walkAnim];

[_guy, _wps] spawn {
	_guy = _this select 0;
	_wps = _this select 1;
	_i = 0;

	//procedure for smooth turning
	_turningProc = {
		_this spawn {
			_guy = _this select 0;
			_wp = _this select 1;
			_dir = [_guy, _wp] call BIS_fnc_dirTo;
			if (_dir < 0) then {_dir = 360 + _dir};
			_degs = _dir - direction _guy;
			if (abs _degs > 180) then {_degs = _degs + (360 * (_degs / abs _degs) * (-1))};
			_step = _degs / 20;
			while {(abs _degs > abs _step) && BIS_scriptedMoveEnabled} do {
				_guy setDir (direction _guy + _step);
				_degs = _dir - direction _guy;
				sleep 0.025
			};
			_guy setDir ([_guy, _wp] call BIS_fnc_dirTo)
		}
	};

	//make sure the unit faces its first waypoint
	[_guy, _wps select 0] call _turningProc;

	//turn the unit at each waypoint
	while {_i < count _wps} do {
		waitUntil {[(position _guy) select 0, (position _guy) select 1] distance [(_wps select _i) select 0, (_wps select _i) select 1] < 0.5 || if (_i > 0) then {(_guy distance (_wps select (_i - 1))) > ((_wps select _i) distance (_wps select (_i - 1)))} else {FALSE}};
		[_guy, _wps select (_i + 1)] call _turningProc;
		textLogFormat ["SCRIPTED WALK: %1 just reached WP #%2 (of %3).", name _guy, _i + 1, count _wps];
		_i = _i + 1
	}
};

waitUntil {[_guy, _wps select 0] call BIS_fnc_relativeDirTo < 30};

//playing walk animations
_i = 1;
while {(_i <= _animLoops && !(isPlayer _guy)) && BIS_scriptedMoveEnabled} do {
	_nic = [objNull, _guy, rPLAYMOVE, _walkAnim] call RE;
	_i = _i + 1;
	sleep 0.5
};

//a code can be executed once the unit finished walking
waitUntil {speed _guy < 0.25};
_guy enableAI "MOVE";
call _code;
};

Looks complicated, but it's not.

Share this post


Link to post
Share on other sites

Kylania - Those behaviors I believe work just for BLUFOR and OPFOR, not civilians.

Blackmamb - Yeah that does look intimidating! Do you know how I am supposed to use it? Do I simply just put it into a script file, then execute the script file in my init.sqf file and civilians SHOULD automatically be ok with walking on roads?

Thanks for your help!

Share this post


Link to post
Share on other sites

Nah, not THAT simple , though!

First, this function is already somewhere in your game if you have ACR or ACR lite.

Basically the point of this is to hard-script movement for a unit following an array of positions.

It is called this way:

[_unit, [[i]array of positions[/i]], {[i]code to execute after finishing walking[/i]}] spawn BIS_movingProc;

Where _unit would be your civilian name.

You could create a few markers you want your guy to pass by, and have it look like this

[myCivilian, [getMarkerPos "mkr1", getMarkerPos "mkr2", getMarkerPos "mkr3", getMarkerPos "mkr4", getMarkerPos "mkr5", getMarkerPos "mkr"], {hint "I'm there!"}] spawn BIS_movingProc;

The unit called myCivilian would walk to each of those markers, and when he gets to the last one you would get a hint.

Note that I haven't tested that one out yet, just stumbled across this the other day.

It will probably be a resource hog, so use it with moderation (don't try and have fifty units executing this at the same time, i guess. But that's cinema, right? Special effects and suggestion, plus montage, buddy).

Edit: just tested it, works fine but is designed for a running animation. It would need a bit of work to do it with a walking animation (basically just finding the corresponding animation length).

Plus i forgot to mention, for people interested, it needs a functions Module on the map, and another function must have been called first:

[] call BIS_fnc_initWLib;

Edited by BlackMamb

Share this post


Link to post
Share on other sites

I'm a noob to modules. How exactly do I do a functions module?

My current understanding is (which is probably flawed):

I simply use the code you used [myCivilian.... spawn BIS_movingProc]; the BIS_movingProc is already inside Arma2 you're saying, right?

Do I simply put this in my init.sqf file?

[] call BIS_fnc_initWLib;

Also, can I ask another noob question? I often see the "_" in code such as "_unit". What does the _ mean? Is it to just generate a local variable within that section of code that will get rid of it later? I have a hard time understanding when I need to use a _ and when I don't. Thank you so much again!! :)

Share this post


Link to post
Share on other sites

Not sure if this would work or if its even good enough for you but, make a border/boundary on both side of the roads which only civs cant enter?

Share this post


Link to post
Share on other sites
How exactly do I do a functions module?

Go to the editor, press F7, or go to modules, then in the list look for functions, place it, and your done.

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  

×