Jump to content

# Rectangular unit placement radius

## Recommended Posts

For me the most useful thing for making my missions is to have the ability to place units randomly within a rectangle instead of just a circle.  Is there a way to lay down a trigger, shaped how I want then have a unit randomly start within that trigger shape?

#### Share this post

##### Share on other sites

Yes.

As you know, most of the commands/functions for placing/spawning/moving something in an area, refers to the radius. For example, Bis_fnc_findSafePos   findEmpyPosition    but also selectBestPlaces , waypoints completion radius...

With a rectangle, no more radius question. You can compare x,y coordinates... but that means a North oriented rectangle.

So, what I do, is to manage a randomized position inside a usual circled area (larger than rectangle), with a looped condition exiting  for this position inside the rectangle.

something like:

private _pos = [0,0,0];

While {! (_pos inArea _myRectangle)} do { _pos = _centerOfArea getPos [_circleRadius * sqrt random 1, random 360]; _pos};

#### Share this post

##### Share on other sites

Check the example for a whitelisted array with - [center, [a, b, angle, rect]]

example:

```_rectangle = true;

_radnomRectanglePos = [[[_position, [_xAxis, _yAxis, _rotation, _rectangle]]], _blacklist] call BIS_fnc_randomPos; ```

• 1

#### Share this post

##### Share on other sites
17 hours ago, BlackbirdSD said:

Is there a way to lay down a trigger, shaped how I want then have a unit randomly start within that trigger shape?

Unit init...

```if ( isServer ) then {
this setPos ( [ myTrigger ] call BIS_fnc_randomPosTrigger );
};```

Where myTrigger is the name given to your trigger

• 1

#### Share this post

##### Share on other sites
2 hours ago, Larrow said:

Unit init...

```
if ( isServer ) then {
this setPos ( [ myTr﻿igger ] call BIS_fnc_randomPosTrigger );
};﻿```

Where myTrigger is the name given to your trigger

Perfect thanks.  I hope if they make an Arma 4 they will just include a placement rectangle to make it easier.

#### Share this post

##### Share on other sites

Yes, BIS_fnc_randomPosTrigger is not too bad, and definitely better than whitelisting in  BIS_fnc_randomPos.

Now, for performance, may I suggest you to compare:

[ myTr﻿igger ] call BIS_fnc_randomPosTrigger;

and

private _pos = [0,0,0];
_circleRadius = 1.42 * ((triggerArea myTrigger #0) max (triggerArea myTrigger #1));
While {! (_pos inArea myTrigger)} do { _pos = myTrigger getPos [_circleRadius * sqrt random 1, random 360]; _pos};

#### Share this post

##### Share on other sites
5 hours ago, pierremgi said:

Yes, BIS_fnc_randomPosTrigger is not too bad, and definitely better than whitelisting in  BIS_fnc_randomPos.

Now, for performance, may I suggest you to compare:

[ myTr﻿igger ] call BIS_fnc_randomPosTrigger;

and

private _pos = [0,0,0];
_circleRadius = 1.42 * ((triggerArea myTrigger #0) max (triggerArea myTrigger #1));
While {! (_pos inArea myTrigger)} do { _pos = myTrigger getPos [_circleRadius * sqrt random 1, random 360]; _pos};

What do you mean by test for performance?  See which one works better?

## Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

×

• Clubs