OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: twisted on 20 Mar 2009, 22:10:43
-
my math skills (and trig) are very rusty. So help is appreciated here please.
I want to get scouts to move to a marker (no problem) but using cover to get there (problem).
say the marker is 500m away. I want to divide the path into five points spaced 100m apart along the line (call them A1, B1, C1, D1, E1). and then find the closest cover for each waypoint (call them A2, B2, C2, D2, E2). these points would be stored (not sure how to dynamically allocate the waypoints as i want this to be able to auto adjust for any distance over 100m - help?).
finally the scouts would run to waypoint B2. pause. run to C2. etc. that's no problem either.
how do i (1) calculate the points on a path and (2) then store them in dynamically for (3) easy retrieval.
insights and assistance would be appreciated.
-
Hmm, could be done like this:
#define SECTION_LENGTH 100 // in meters
private ["_fn_getIntermediatePositions","_posPlayer","_posMarker","_sectionCount","_positionList"];
_fn_getIntermediatePositions = {
private ["_pos0","_posN","_sections","_posList","_p","_offsetX","_offsetY"];
_pos0 = _this select 0; // start position
_posN = _this select 1; // end position
_sections = _this select 2; // number of intermediate positions
// offsets to the next position
_offsetX = ((_pos0 select 0) - (_posN select 0)) / _sections;
_offsetY = ((_pos0 select 1) - (_posN select 1)) / _sections;
// generate list of intermediate positions
// starting with the one closest to the end position to make the
// first intermediate position the one with the distance error
_posList = [];
_p = _posN;
for "_i" from 0 to (_sections - 2) do {
_x = (_p select 0) + _offsetX;
_y = (_p select 1) + _offsetY;
_p = [_x,_y];
_posList = [_p] + _posList;
};
// add the last position to list
_posList = _posList + [_posN];
_posList; // return value
};
/* Example Usage
*
* Requires:
* - a marker called "myMarker"
* - a player :)
*/
_posPlayer = getPos player;
_posMarker = markerPos "myMarker"; // mind the quotes!
_sectionCount = (_posPlayer distance _posMarker) / SECTION_LENGTH;
_positionList = [_posPlayer, _posMarker, _sectionCount] call _fn_getIntermediatePositions;
// place a marker at each position
for "_i" from 0 to (count _positionList - 1) do {
_name = "marker" + str(_i);
_pos = _positionList select _i;
_markerstr = createMarker[_name, _pos];
_markerstr setMarkerShape "ICON";
_markerstr setMarkerType "DOT";
_markerstr setMarkerText str(_i);
};
-
thanks! i see the array info you helped me with last time has a place here. i also learnt how to use return values from your example. that was something else new. :D
ediT - question. why did you define _fn_getIntermediatePositions as private. i haven't seen a function defined as private before and would like to understand more.
edit2 - i am unsure as how to execute the code you shared.
-
Function defined as private:
That's just a {} code snippet, like any other, contained inside the local variable _fn_getIntermediatePositions; which can be made private just like any other local variable.
_codesnippet = {_dude = _this select 0; _dude setdamage 1;};
[player] spawn _codesnippet;
>> Player dies ;)
Just a tiny note: default ArmA AI behaviour has them move from cover to cover when travelling from A to B anyway, although not in a controlled fashion like you're trying here. While in Stealth or Combat however they will attempt to travel via things they consider cover (such as bushes) -> of course you can't control them and tell them to stop or anything like that, but anyway. Just a note.
Wolfrug out.