Jump to content
Sign in to follow this  
BatSpoggy

Randomized unit position with relative position retained?

Recommended Posts

Hi, I've been searching for an answer to this question for ages and haven't got anywhere, so I though it best to ask here.

Is there any way to place units (say the player unit) with a certain placement radius, but retain the position of all other units relative to that one?

So for example, place the player in the middle of the map with an enemy unit 100m north, and set the player placement radius to 1000m but keep the enemy unit always 100m north of wherever the player appears.

The best thing would be the ability to then randomize the distance and bearing from the player within set parameters, but I'm guessing that isn't possible.

I am interested in this for the purpose of creating randomized small-scale engagements, because while I enjoy the likes of DUWS, I'd really like to be able to make a "Random Instant Action" without having to place a framerate-killing number of OFPOR and then randomize the starting location, it's really crude and I'd like to polish my idea enough to eventually release for others to enjoy.

Cheers

Share this post


Link to post
Share on other sites

I don't know how to do it as in what functions etcetera to use but I think what you want to do is have an object (Can be a marker or the player in this case) randomize its position, then you'll have to get the position of that object and set the other objects to move to a position that's well 100m north of it, so you truly only got 1 thing that is random with everything else being moved to a relative position of it.

Share this post


Link to post
Share on other sites

That's what I was thinking, I only want to randomize the position of one thing and then have the others move to the same position relative to it.

I know this works in some sense because if a group leader has a random placement set their subordinate units will spawn in formation at the leaders (random) position, what I'm trying to establish is how you was make a whole "system" of units (and markers, preferably) do the same thing.

There's a huge amount of editing knowledge here, so I'm sure somebody must know a way.

Share this post


Link to post
Share on other sites

Place this into your debug console and hit the LOCAL EXEC button. You will end up with a perfect circle around the player.

0 = [] spawn { while {true} do {_spawnPos = [position player, 100 , random 360] call BIS_fnc_relPos; _heliPad = createVehicle ["Land_HelipadRescue_F", _spawnPos, [], 0, "NONE"]; sleep .5;};};

This is what it looks like after I move the player 3 times.

relpos_zpsef260c0b.jpg

---------- Post added at 12:15 ---------- Previous post was at 12:01 ----------

So if you only want units to spawn 100 meters north of you, you would do this:

0 = [] spawn { while {true} do {_spawnPos = [position player, 100 , random 45] call BIS_fnc_relPos; _heliPad = createVehicle ["Land_HelipadRescue_F", _spawnPos, [], 0, "NONE"]; sleep .5;};};

I used random 45 so I could see them actually spawn in. Place those codes into the debug console for testing and you will see what I mean. This is what it looks like:

relpos2_zps5f4ef928.jpg

Edited by cobra4v320

Share this post


Link to post
Share on other sites
Place this into your debug console and hit the LOCAL EXEC button. You will end up with a perfect circle around the player.

0 = [] spawn { while {true} do {_spawnPos = [position player, 100 , random 360] call BIS_fnc_relPos; _heliPad = createVehicle ["Land_HelipadRescue_F", _spawnPos, [], 0, "NONE"]; sleep .5;};};

And here I thought we had to roll our own functions to get relative position. Good to know that BIS_fnc_relPos exists

Share this post


Link to post
Share on other sites

@cobra4v320:

Brilliant, thanks for that! I fiddled with it a little to make it work in the init field and came up with this:

pos = [position player, 100 , random 360] call BIS_fnc_relPos; this setPos (pos);

It works perfectly and seems to allow me to basically copy-paste for simplicity, as I managed to move an empty helicopter to 25m away and an ammobox 5m away with them both using independent directions from the player (helicopter spawned in front, box behind).

By naming the unit leaders I take it I can have other groups spawn relative to the moved groups by replacing "player" with "unit1" or whatever, presumably with a short wait command to ensure the group has already moved to its relative position?

Is it possible to set the distance (100) in the above example to a random value within a range? I can set random 100 and it is random within 100m, but is it possible to set something like "random 100-200" to get a random distance between 100m and 200m.

Thanks a lot, this has eluded me literally for months, I'm very grateful.

Share this post


Link to post
Share on other sites
[position player, 100 + (random 100) , random 360] call BIS_fnc_relPos;

Share this post


Link to post
Share on other sites

Just to confirm, BIS_fnc_relPos differs from modelToWorld in that it also gets a relative direction?

Share this post


Link to post
Share on other sites

//find position relative to passed position
if (count _pos==3) then
{
_pos = [(_pos select 0) + _dist*sin _dir, (_pos select 1) + _dist*cos _dir, _pos select 2];
}
else
{
_pos = [(_pos select 0) + _dist*sin _dir, (_pos select 1) + _dist*cos _dir];
};
_pos

There is also bis_fnc_relPosObject which uses modeltoworld

Share this post


Link to post
Share on other sites
[position player, 100 + (random 100) , random 360] call BIS_fnc_relPos;

Oh yeah, I used something like that ages ago but had forgotten about it.

I've gotten my mission working almost exactly as intended now, just need to polish it up a little and add a briefing, thanks.

Does this function work in ArmA 2 as well?

Share this post


Link to post
Share on other sites

I looked under functions viewer selected A2 > ALL and its under A2 so my best guess is yes. You could always copy the function and use it that way.

Here is the function:

scriptName "Functions\geometry\fn_relPos.sqf";
/************************************************************
Relative Position
By Andrew Barron

Parameters: [object or position, distance, direction]

Returns a position that is a specified distance and compass
direction from the passed position or object.

Example: [player, 5, 100] call BIS_fnc_relPos
************************************************************/

private ["_pos","_dist","_dir"];

_pos  = _this select 0;
_dist = _this select 1;
_dir  = _this select 2;

//if an object, not position, was passed in, then get its position
if(typename _pos == "OBJECT") then {_pos = getpos _pos};

//find position relative to passed position
if (count _pos==3) then
{
_pos = [(_pos select 0) + _dist*sin _dir, (_pos select 1) + _dist*cos _dir, _pos select 2];
}
else
{
_pos = [(_pos select 0) + _dist*sin _dir, (_pos select 1) + _dist*cos _dir];
};
_pos

---------- Post added at 20:00 ---------- Previous post was at 19:58 ----------

You can also do it this way:

_dir = [player, getpos dude] call BIS_fnc_relativeDirTo;
_pos = [player, 5, _dir] call BIS_fnc_relPos;
_pos

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  

×