Jump to content
Sign in to follow this  
theend3r

ATL to AGL(S)

Recommended Posts

I'm randomly spawning AI using bis_fnc_findSafePos but I don't want them to be spawned on buildings/containers etc. How do I get ATL - AGL(S)?

Example: I put myself on a container in a harbor that is a part of the map and run

hint str [getPosATL player, getPos player]

which returns [[13330.7,12197.6,5.23744],[13330.7,12197.6,0.00143862]].

This is not a problem with objects but when working purely with coordinates, I have no idea how to get the 5.23 from the 0.

Share this post


Link to post
Share on other sites

_joueurs = playableUnits;
_nombre = round(random ((count _joueurs)-1));
_cible = _joueurs select _nombre;
_targetPos = getPos _cible;

_posecentre = _targetpos;
_start_distance = 300; // raduis of the spawn

    _xpos = _posecentre select 0;
    _ypos = _posecentre select 1;
    _zpos = _posecentre select 2;
    _distance = _start_distance;
                        _angle = random 360;
    _xxpos = (_distance * cos _angle);
    _yypos = (_distance * sin _angle);
    _xpos = _xpos + _xxpos;
    _ypos = _ypos + _yypos;
    _posecentre set [0, _xpos];
    _posecentre set [1, _ypos];
    _posecentre set [2, _zpos];
 
mysoldier setpos _targetpos; 
For ramdom spawn by player  it ' s my solution the script work only on MP session no into the editor by;)) good edition

Share this post


Link to post
Share on other sites
16 minutes ago, Nach said:

*snip*

That doesn't help at all but thanks for replying. :smile_o:

Share this post


Link to post
Share on other sites
1 minute ago, theend3r said:

That doesn't help at all but thanks for replying. :smile_o:

 

marker =["P1","P2","P3","P4","P5","P6","P7","P8","P9","P10",
  "P11","P12","P13","P14","P15","P16","P17","P18","P19","P20",
  "P21","P22","P23","P24","P25","P26","P27","P28","P29","P30",
  "P31","P32","P33","P34","P35","P36","P37","P38","P39"]; // marker on map

 

_nombre = round(random ((count marker)-1));
_mkr = marker select _nombre;

 

myslodier setPos getMarkerPos _mkr;

 

 

Share this post


Link to post
Share on other sites
2 minutes ago, Nach said:

 

marker =["P1","P2","P3","P4","P5","P6","P7","P8","P9","P10",
  "P11","P12","P13","P14","P15","P16","P17","P18","P19","P20",
  "P21","P22","P23","P24","P25","P26","P27","P28","P29","P30",
  "P31","P32","P33","P34","P35","P36","P37","P38","P39"]; // marker on map

 

_nombre = round(random ((count marker)-1));
_mkr = marker select _nombre;

 

myslodier setPos getMarkerPos _mkr;

 

 

By "doesn't help at all" I meant that I don't need a spawning script, I have mine. I need what I wrote I need: ATL - AGL(S) for a coordinate array. AGLStoATL.

  • Like 1

Share this post


Link to post
Share on other sites

oki  you want to check the surface it 's that?

 

if (!surfaceIsWater position player) then { myscript }; // for the land or

 

if (surfaceIsWater position player) then { myscript  }; // fot he sea

 

or if (!surfaceIsWater position player) then { mylandscript  }else{ myseascript  };

 

Share this post


Link to post
Share on other sites
2 hours ago, kauppapekka said:

Well from the topic title I would guess:

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

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

 

But from the post itself I would need a little clarifying, as you say you don't want the units on top of the stuff yet in the example you want the ATL height that is on top of the object?

 

ATL, if I understand it correctly, is the only way to tell if I stand on top of a map (not editor) placed structure. Like in my example, ATL returns a height of 5.23744.

The problem is that we have all these functions for ASL -> ATL...etc. but not one for AGLS -> ATL or AGSL -> anything because "As there is currently no way to obtain H of the surface, it becomes impossible to convert given PositionAGLS into other formats" - biki. And of course getPos / setPos (and thus also bis_fnc_findSafePos, btw) take AGLS. :face_palm:

 

Is there any simple way to check if a position (not an object) is on top of a building / container / ... ? I guess terrainIntersect or something similar could do it but it seems a bit ridiculous and demanding to do it potentially many times.

 

Edit: To make things even more ridiculous, player setPos getPos player, when used from the top of a container pile (in Blue Pearl industrial port, Tanoa) places you down inside of it.

Share this post


Link to post
Share on other sites

player setposATL getposATL player should work better. not sure if the double ATL is even needed but i know normal setpos has a tendency to put you on terrain, which is intended i think.

 

i'm thinking that once you have a position you will only have an array of 3 numbers. don't think you can reverse engineer the format. it's more about what setpos type you use it with.

 

how are you creating your positions?

 

i found a good way to get a safe position on the terrain is temporarily spawning an invis helipad using createVehicle (array version) and setting the last parameter to "NONE". then you can getpos the positon of it and delete it. the engine makes sure to spawn it in a good position. so you can abuse that to get good positions.

 

sorry for the generic info. still not 100% sure what you need.

  • Like 1

Share this post


Link to post
Share on other sites
12 minutes ago, bad benson said:

player setposATL getposATL player should work better. not sure if the double ATL is even needed but i know normal setpos has a tendency to put you on terrain, which is intended i think.

 

i'm thinking that once you have a position you will only have an array of 3 numbers. don't think you can reverse engineer the format. it's more about what setpos type you use it with.

 

how are you creating your positions?

 

i found a good way to get a safe position on the terrain is temporarily spawning an invis helipad using createVehicle (array version) and setting the last parameter to "NONE". then you can getpos the positon of it and delete it. the engine makes sure to spawn it in a good position. so you can abuse that to get good positions.

 

sorry for the generic info. still not 100% sure what you need.

Yes, what I'm trying to do is definitely achievable by using a virtual/invisible "pointer" that runs getPosATL pointer but I was trying to do it purely with numbers/arrays as I have to run this potentially about 40 times at once (not every frame but still) when spawning enemies and it could result in a visible slowdown if I had to spawn and move around some invisible pointer (probably not but...). For now I can do it with ((AGLToASL _pos) select 2) > 6 since I know the terrain and it's basically flat but it limits me.

 

I will probably go this way anyway. Thanks for the input.

Share this post


Link to post
Share on other sites

but how are you creating your positions though? would still like to know.

Share this post


Link to post
Share on other sites

Through bis_fnc_findSafePos, like I said.

Spoiler

_pos = [0,0,80];
while {(((AGLToASL _pos) select 2) > 6) || !(lineIntersects [eyePos player, (AGLToASL _pos) vectorAdd [0,0,1], player])} do {
	_pos = ([getPos leader group player, 200, 300, 3, 0, 70, 0] call BIS_fnc_findSafePos) + [0]
};

To make sure they spawn out of sight. This is in harbor so (((AGLToASL _pos) select 2) > 6) makes the spawn on the ground and not much higher.

It works well for my needs and honestly there's no need to modify it but it excludes one uphill part of the location.

 

The function itself checks for object proximity so there's probably no need to do this anyway but I simply wanted to know if it's possible.

  • Like 1

Share this post


Link to post
Share on other sites
/*
	example: 
	#1. [objNull] call SM_fnc_setPosAGLS;
	#2. [objNull, [0,0,0]] call SM_fnc_setPosAGLS;
	inputs:
	#1, object.
	#2, (optional) position.
*/

params ["_object","_position"];

try
{
	if (isNil "_object") throw false;
	if (isNull _object) throw false;

	if (isNil "_position") then
	{
		_position = getPos _object;
	};

	_position set [2, worldSize]; 
	_object setPosASL _position;

	_position set [2, vectorMagnitude (_position vectorDiff getPosVisual _object)];
	_object setPosASL _position;
}
catch
{
	// Maybe do some logging? 
};

true

Accepts, ASL, ATL, etc.., or just 2d. 

 

in your case:

 

_position = [blah,blah] call BIS_fnc_findSafePos;
[_unit, _position] call SM_fnc_setPosAGLS

 

 

Is this what you're looking for? this should put the units on-top of rocks etc..

Share this post


Link to post
Share on other sites
28 minutes ago, stokesgamingmc said:

Is this what you're looking for?

No. I'll try to make it as simple as possible. I want to get this

hint str (((getPosATL object) vectorDiff (getPos object)) select 2)

without referencing any non-default object, i.e. purely from the map/coordinates (coordinates equal to getPos object). I guess it's not possible but it's OK, this was just out of curiosity.

Thanks for the replies everyone.

Share this post


Link to post
Share on other sites
5 minutes ago, theend3r said:

No. I'll try to make it as simple as possible. I want to get this


hint str (((getPosATL object) vectorDiff (getPos object)) select 2)

without referencing any non-default object, i.e. purely from the map/coordinates. I guess it's not possible but it's OK, this was just out of curiosity.

Thanks for the replies everyone.

Explain to me what exactly you're trying to do and i can give you what you want, i have many functions for position finding etc.. one of them probably is what you're looking for.

 

Share this post


Link to post
Share on other sites
3 minutes ago, stokesgamingmc said:

Explain to me what exactly you're trying to do and i can give you what you want, i have many functions for position finding etc.. one of them probably is what you're looking for.

 

Try the above with player. It's 0 while on ground, 0 when climbing a ladder or falling but positive when standing on the top of a structure. The problem is that the commands available can only work with a reference object, not coordinates. I can just move an invisible helipad around like @bad benson said but I wanted to avoid that.

Share this post


Link to post
Share on other sites
2 minutes ago, theend3r said:

Try the above with player. It's 0 while on ground, 0 when climbing a ladder or falling but positive when standing on the top of a structure. The problem is that the commands available can only work with a reference object, not coordinates. I can just move an invisible helipad around like @bad benson said but I wanted to avoid that.

Are you trying to get the height on-top of something without a object?

Share this post


Link to post
Share on other sites
6 minutes ago, stokesgamingmc said:

Are you trying to get the height on-top of something without a object?

Yes.

Share this post


Link to post
Share on other sites
8 minutes ago, theend3r said:

Yes.

/*
	example:
	_position call SM_fnc_getPositionHeight;
	returns:
	position ASL
*/

private _position = _this;

try 
{
	if (isNil "_position") throw false;

	_position set[2, 0];

	private _positionH = +_position;
	_positionH set[2, worldSize];

	private _surface = lineIntersectsSurfaces [_positionH,_position,objNull,objNull,false,1,"GEOM","NONE"];

	if ((count _surface) != 0) then
	{
		_position = (_surface select 0) select 0;
	};
}
catch
{
	_position = [];

	// Do some logging?
};

_position

maybe this?

 

//edit: fixed typo

Share this post


Link to post
Share on other sites

Nope, doesn't work. Returns 0 at the roof of the building where I do my testing (Tanoa, [13268,12239,0]) whereas (((getPosATL player) vectorDiff (getPos player)) select 2) returns the correct height of the building (9.7 - also visible when placing units in the editor in their z value).

 

Still, I'm sure this approach of using the intersect commands is correct. I'll have to give up today but I'm sure I can work it out if I try.

 

21 minutes ago, stokesgamingmc said:

Did you try it after i fixed the typo? lol

 

I did.

Share this post


Link to post
Share on other sites
3 minutes ago, theend3r said:

Nope, doesn't work. Returns 0 at the roof of the building where I do my testing (Tanoa, [13268,12239,0]) whereas (((getPosATL player) vectorDiff (getPos player)) select 2) returns the correct height of the building (9.7 - also visible when placing units in the editor in their z value).

 

Still, I'm sure this approach of using the intersect commands is correct. I'll have to give up today but I'm sure I can work it out if I try.

Did you try it after i fixed the typo? lol

Share this post


Link to post
Share on other sites

@theend3r you should do what you mentioned yourself. try lineintersectsSurfaces. it will give you the intersection postion and should work against terrain. not sure if that plus then making a new pos, if it should be elevated is faster than createVehicle array. but should be easy to compare.

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  

×