Jump to content
1para{god-father}

Help on Random Spawn direction

Recommended Posts

Need some help please

I have marker 200x200" and I would like a continuous AI spawning once dead , but I need them to spawn in a Random direction each time and also be at a random distance out from the marker i.e 300-800m but if any Players are near say 100m try another direction.

I am using UPS so they then will patrol back into the marker and start patrolling again.

Any idea how i can do that ?

SpawnEnemies = true; // start spawning

while {SpawnEnemies} do {
_Grp1 = [getPos hpad1, EAST, 3] call BIS_fnc_spawnGroup;  // spawn in AI
       [(units _Grp1) select 0, "Base1"] execVM "ups.sqf";     // walk or run back to Marker and patrol again
waitUntil {{alive _x} count (units _Grp1) == 0};        // wait until all units dead and spawn next group but at a random direction again.
};

Share this post


Link to post
Share on other sites

You could get a random position for the marker "hpad1"

try out

SpawnEnemies = true; // start spawning

if (!isserver) exitwith {};

while {SpawnEnemies} do {
_Grp1 = [getPos hpad1, EAST, 3] call BIS_fnc_spawnGroup;  // spawn in AI
       [(units _Grp1) select 0, "Base1"] execVM "ups.sqf";     // walk or run back to Marker and patrol again
waitUntil {{alive _x} count (units _Grp1) == 0};        // wait until all units dead and spawn next group but at a random direction again.

        _centerpos = (getmarkerpos "hpad1");                      // sets the centerpoint
        _dir = random 360;                                               // sets the direction
        _range = random 200;                                          // sets the max range. If you want a min range just add it to it [ex: (random 200) + 10]

       "hpad1" setmarkerPos [(_centerPos select 0) + (sin _dir) * _range, (_centerPos select 1) + (cos _dir) * _range, 0];
};

I'm gonna try this out and come back to you in a bit, hope it helps.

Edited by mantls

Share this post


Link to post
Share on other sites

Is it possible to set random direction on newly spawned group/unit? It is always watching north but I need to be randomly directed because those units are guarding zone so there is no sense to guard it if I always know that if come from south it will be easy to enter unnoticed..  

I tried this:

myUnit = createGroup east createUnit ["O_Soldier_F", [12400,3566,8], [], 0, "NONE"];

_dir = random 360; 

myUnit setDir = random 360;   

 

OR:

muUnit = createGroup east createUnit ["O_Soldier_F", [12400,3566,8], [], 0, "NONE"];

_dir = random 360; 

myUnit setDir = _dir

 

But no work.. Thanks in advance

 

EDIT:  Or replacement for this could be if they can be set to scan horizon somehow, so view direction change all time?

Share this post


Link to post
Share on other sites
_myUnit = (createGroup east) createUnit ["O_Soldier_F", getpos player, [], 0, "NONE"]; 
_myUnit setDir (random 360);  

@Nemanjic just follow @beno_83au's advice next time

  • Thanks 1

Share this post


Link to post
Share on other sites

Thank you guys @Smart Games @beno_83au it solves.  It is hard for me to understand alone the ways code is working and write it up, but it get easier when I see final result. Thanks guys 🥤🍻

  • Like 1

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

×