Jump to content
Sign in to follow this  
Fragmagnet

Randomly place an object around a randomly placed object.

Recommended Posts

In the editor, there is the placement radius option for units and such.

Here's what I want to do.

Unit 1 has a placement radius of 1km

unit 2 has a placement radius of 75 meters.

I want unit 2's placement radius to be around Unit 1's random placement.

It seems like it would be possible through the init of the unit. I just can't figure out how.

Also doing this without grouping unit 1 and 2 together.

Also preferrably completely through the editor and not some SQF.

Edited by Fragmagnet

Share this post


Link to post
Share on other sites

In unit1's init place this

dir = random 360;
radius = 75;
posx = (sin dir) * (random radius);
posy = (cos dir) * (random radius);
unit2 setPosATL (this modelToWorld [posx, posy, 0]);

Remove the placement radius off of unit2.

When unit1 spawns it will place unit2 somewhere within 75m of him.

Share this post


Link to post
Share on other sites

if I do that with a teamleader however, the grouped units do not go with him, and with that method, if you're on a hill units can spawn in the air and fall (either they spawn in the air or fall, or they spawn in each other and one gets pushed up and then falls).

Would it be possible to actually delay the spawn of units until their leader gets placed around unit1

because that way they would just spawn into formation after the leader is placed.

Edited by Fragmagnet

Share this post


Link to post
Share on other sites
if I do that with a teamleader however, the grouped units do not go with him, and with that method, if you're on a hill units can spawn in the air and fall (either they spawn in the air or fall, or they spawn in each other and one gets pushed up and then falls).

Would it be possible to actually delay the spawn of units until their leader gets placed around unit1

because that way they would just spawn into formation after the leader is placed.

Just add:

unit2 setpos [(getpos unit2) select 0,(getpos unit2) select 1, 0];

You might want to use Foreach though to make the Script a bit more Open.

Share this post


Link to post
Share on other sites

objectPos = [firstObject,4,random(360)] call bis_fnc_relPos;

4 = radius from center, firstObject

Share this post


Link to post
Share on other sites
if I do that with a teamleader however, the grouped units do not go with him,
Erm of course, your initial statement was one unit around another unit.
if you're on a hill units can spawn in the air and fall
Yes , my fault forgot to set ATL height to 0.
they spawn in each other
Again original statement said nothing about moving a group.

Try this

toMove = unit2;
relTo = unit1;
radius = 50;
pos = [relTo, radius, random(360)] call BIS_fnc_relPos;
pos set [2,0];
offsets= [];
{
	unitOffset = ([pos, (_x distance toMove), [toMove,_x] call BIS_fnc_dirTo ] call BIS_fnc_relPos);
	unitoffset set [2,20];
	endpos = unitoffset;
	for "_i" from 0.25 to 20 step 0.25 do {
		endpos set [2, _i];
		if (!(lineIntersects [ATLToASL unitoffset, ATLToASL endPos])) exitWith {endpos set [2, _i]};
	};
	offsets set [_forEachIndex, endpos];
}forEach units group toMove;
{_x setPosATL (offsets select _forEachIndex);} forEach units group toMove;

Moves whole group and places them back down exactly like they were. Also after some testing south of the light house at Kamino firing range (big elevation changes and large terrain objects) it even checks that its not moving one of the units into a rock or other object.

Edited by Larrow

Share this post


Link to post
Share on other sites

Possibly off-topic question, but it is slightly related.

Does Placement Radius provide a means to randomly place vehicles, ammo crates, etc?

I was looking for a script/method to randomly place vehicles and gear boxes across the entire map.

Share this post


Link to post
Share on other sites
[color="#FF8040"][color="#1874CD"]_p[/color] [color="#8B3E2F"][b]=[/b][/color] [color="#191970"][b]getPos[/b][/color] unit1[color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_p[/color] [color="#191970"][b]vectorAdd[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#FF0000"]75[/color] [color="#8B3E2F"][b]-[/b][/color] [color="#191970"][b]random[/b][/color] [color="#FF0000"]150[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]75[/color] [color="#8B3E2F"][b]-[/b][/color] [color="#191970"][b]random[/b][/color] [color="#FF0000"]150[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color]
[color="#1874CD"]_p[/color] [color="#191970"][b]set[/b][/color] [color="#8B3E2F"][b][[/b][/color][color="#FF0000"]2[/color][color="#8B3E2F"][b],[/b][/color] [color="#FF0000"]0[/color][color="#8B3E2F"][b]][/b][/color][color="#8B3E2F"][b];[/b][/color] [color="#006400"][i]//make sure unit2 doesnt spawn in air[/i][/color]
unit2 [color="#191970"][b]setPos[/b][/color] [color="#1874CD"]_p[/color][color="#8B3E2F"][b];[/b][/color][/color]

Made with KK's SQF to BBCode Converter

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  

×