Jump to content

# spawning objects in radius of random placed objects.

## Recommended Posts

hi guys.

for a new mission concept i am looking for a way to spawn object-B (a car) somewhere within a 500meter radius from object-A (unit)

Object-A is randomly placed with the RANDOM markers.

are there script i could use of any other ways. ( or maybe pre placing object-B's and spawning the with createvehicle if object-B) is in a triggers range. (but this will ruin the search and recover part of the mission)

thanks in advance.

jptiger

#### Share this post

##### Share on other sites

There is a function called BIS_fnc_relPos that you should look. You pass to it an object or position (in your case Object A), a desired distance, and a direction in degrees. If you combine this function with BIS_fnc_randomInt, you can randomize the distance and direction each time object B spawns. Example:

```private ["_distance", "_direction", "_randomPos"];

_distance = [1,500] BIS_fnc_randomInt; // Random distance between 1 and 500m.

_direction - (0,359] BIS_fnc_randomInt; // Random direction between 0 and 359 degrees.

_randomPos = [myObject, _distance, _direction] call BIS_fnc_relPos; // The position at the random distance and random direction from myObject (rename myObject as required).```

#### Share this post

##### Share on other sites

You can just take object position and do this to x and y

x = x - 500 + random 1000

y = y - 500 + random 1000

this will give you random x,y in 500 metres radius. However to find empty spot you need to use

isFlatEmpty, selectBestPlaces, findEmptyPosition

#### Share this post

##### Share on other sites
There is a function called BIS_fnc_relPos that you should look. You pass to it an object or position (in your case Object A), a desired distance, and a direction in degrees. If you combine this function with BIS_fnc_randomInt, you can randomize the distance and direction each time object B spawns. Example:

```private ["_distance", "_direction", "_randomPos"];

_distance = [1,500] BIS_fnc_randomInt; // Random distance between 1 and 500m.

_direction - (0,359] BIS_fnc_randomInt; // Random direction between 0 and 359 degrees.

_randomPos = [myObject, _distance, _direction] call BIS_fnc_relPos; // The position at the random distance and random direction from myObject (rename myObject as required).```

so you place function module on the map,

but do i have to place the code in the init of object-B (car)

myobject is Object-A (unit)?

#### Share this post

##### Share on other sites

I have been searching for the answer to this myself and have finally worked it out!

Place a Bluforce soldier on the map (you) so you can see the results.

Place an Independent soldier on the map and name him green1

Place a truck on the map and name it truck1. Every time the mission starts the truck will start at a place at random within a radius of 50 meters.

I want green1 to start adjacent to the truck.

I start with green1 setPos (getPos truck1); Unfortunately the man starts as a part of the truck machinery and soon dies!

So, we have to find an offset.

In one of the posts above it was commented there are 3 axis, x, y and z. In the formulas below these are named 1, 2 and 3 ( I am not a programmer so I donâ€™t know why!)

In the editing manual I found this:

green1 setPos [getPos truck1 select 0, getPos truck1 select 1, (getPos truck1 select 2) +1000];

This causes green1 to start 1,000 meters above the truck. So, I amend the formula. Specifically I need the offset to be an offset to variable 0 or 1. We clearly donâ€™t want an offset to variable 2!

New formula:

green1 setPos [(getPos truck1 select 0) +0, (getPos truck1 select 1) +0, (getPos truck1 select 2) +0];

Now we are back to the start with the man stuck in the truck.

Solution:

green1 setPos [(getPos truck1 select 0) +20, (getPos truck1 select 1) +0, (getPos truck1 select 2) +0];

The man is now at ground level 20 meters from the truck! Whoo!

And the other version:

green1 setPos [(getPos truck1 select 0) +0, (getPos truck1 select 1) +20, (getPos truck1 select 2) +0];

The man is still 20 meters from the truck! So, both formula work. At this point I cannot state whether the man is front, back, left or right of the truck.

However after a 3 month search I am happy that it works!

.

.

## Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

×

• Clubs