Jump to content
Sign in to follow this  
viel.kuul.10

Random start position for unit in marker

Recommended Posts

How to make a unit (or more units) start at a random position within a marker? I have a simple code for random select markers, but I don't have for radius, direction.

 

this setpos (getMarkerPos (selectRandom ["marker1", "marker2"]));

 

This code I put in a unit init. I don't like sqf.

 

I am trying: this setpos getMarkerPos ["marker1", "marker2"] getPos [random(40), random(360). random(40) is radius. But doesn't works.

Share this post


Link to post
Share on other sites
58 minutes ago, viel.kuul.10 said:

I don't like sqf.

 

It's all .sqf. Get used to it!

 

In unit init:

nul = this spawn { 
    _marker = (selectRandom ["marker1", "marker2"]); 
    _pos = _marker call BIS_fnc_randomPosTrigger;
    _this setPos _pos;
};
  • Like 2

Share this post


Link to post
Share on other sites

It works. I bow to you. 

 

I have a question: how to implant direction to this code? Random or selected?

Share this post


Link to post
Share on other sites

Random:

nul = this spawn {  
    _marker = (selectRandom ["marker1", "marker2"]);  
    _pos = _marker call BIS_fnc_randomPosTrigger; 
    _this setPos _pos;  
    _dir = random 359;
    _this setFormDir _dir;
    _this setDir _dir;
 };

If you want a specific direction, change "random 359" to your desired heading:

nul = this spawn { 
    _marker = (selectRandom ["marker1", "marker2"]); 
    _pos = _marker call BIS_fnc_randomPosTrigger;
    _this setPos _pos;
    _this setFormDir 175;
    _this setDir 175;
};

 

Some invaluable links:

 

The Basics - 

https://community.bistudio.com/wiki/SQF_Syntax

https://community.bistudio.com/wiki/Introduction_to_Arma_Scripting

 

Commands and Functions - 

https://community.bistudio.com/wiki/Category:Scripting_Commands

https://community.bistudio.com/wiki/Category:Arma_3:_Functions

 

Event Handlers - 

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers

https://community.bistudio.com/wiki/Arma_3:_Mission_Event_Handlers

Edited by Harzach
I forgot about setFormDir!
  • Like 2

Share this post


Link to post
Share on other sites

Does not work. If I manually turn the soldier in the desired direction, it spawn in that direction.

 

I am always wishful to learn scripting.

Share this post


Link to post
Share on other sites

Being an AI, you might need to set the formation direction first:

_dir = random 359;
_this setFormDir _dir; 
_this setDir _dir;

Aside from that, Harzach's example does work.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
56 minutes ago, beno_83au said:

Being an AI, you might need to set the formation direction first:

 

Yes, I absolutely apologize, I overlooked that detail. Without first using setFormDir, units are set to the designated heading but then instantly spin around to face their original/previous heading +/- a few degrees.

 

Thanks @beno_83au!

  • Like 2

Share this post


Link to post
Share on other sites

I don't know the actual scripting but this is the sequence.

 

Select a unit.

Find a way to set the unit direction at random

Find a script to read that direction.

Now use that result to have the other units face that direction

 

If you have a leader, and his direction is set at random at (say) 98, when the mission stars all the members of his team will get into formation which means they will turn and face at more or less 98.

.

.

 

 

 

Share this post


Link to post
Share on other sites

@viel.kuul.10 You'll need to expand a bit on the code for groups, but for a turret there's no change (same as a vehicle too).

 

Groups:

Place the code in the Init field of the group leader. You'll need to account for the other AI in the group though, because the previous code will only move the leader and everyone else will have to run (potentially a long way) to get into position. Also, you need to set your random settings BEFORE going into the forEach loop, otherwise each unit will pick it's own random position/direction/etc:

nul = this spawn {
	_marker = (selectRandom ["marker1", "marker2"]);
	_pos = _marker call BIS_fnc_randomPosTrigger;
	_dir = random 359;
	{
		_x setPos _pos;
		if (leader _x == _x) then {
			_x setFormDir _dir;
		};
		_x setDir _dir;
	} forEach (units _this);
};

The other units in the group will still have to run into their formation position, but it's a short run and this is a simple solution.

 

Turrets:

Place Harzach's code in the Init field of the turret itself.

 

There's different things you could do here, like setting each unit in a group to be facing different directions or having a turret/vehicle face one direction but aim at another, and those cases are pretty easy to search for. Then you've just got to read through some forum posts and check out the command wiki and basic things like this will become pretty easy to do pretty quickly.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Works this with a group. I gave you a trophy.

 

Earlier I tested with a turret and a vehicle, every works with that code in the first posts. Only I would like the group to be together with the turret, not just one AI, I usually set up several more AI in the same group. To protect the turret or to replace staff if they die. I realized that any AI that is located in a turret or vehicle, spawns normally but an AI that is outside of a turret or vehicle has to run a long way to find its leader.

 

I'm definitely still learning to scripting. Your codes can help me. I visit community.bistudio.com/wiki often to learn. Of course, I’m going to look at the other links they left here.

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  

×