# Getpos, setpos and absolut heigth

## Recommended Posts

Well, i am desperated.

The rules of logic dont work on Flashpoint scripting, i donÂ´t know why but thats the truth.

I have been working on a script for quite a while, this script creates a bomb at a given distance of the target and add to the bomb some velocity. If every thing is well calculated, the bomb will always hit the rigth spot, the target itself.

This script is not as simple as it will look at a first glance, you had to know the real heigth at sea level of the target, and the real heigth at sea level of the ground at the X,Y point where the bomb is intended to be created.

If you got this two variables, you can calculate the diference, and if you add this diference to a given heigth (the heigth above the target in which you whant the bomb to be created) you will have the point of departure of the bomb.

If you do this well, the relative distance and altitude of the bomb departure point and the target will be the same werever the target is located on the map.

I have managed my self to calculate the mencioned data, the heigth at sea level, distance, initial velocity ect...

But...

But when i use "setpos" to put the bomb where the bomb is intended to departure, the bomb is created at a diferent heigth.

Let me explain:

- I got the heigth at sea level and the diference which is called _dif

- The altitude in wich the bomb should be created had to be 150 + _dif = _alt

- I gave the order to the bomb, via setpos [x,y, _alt], but for some reason, the bomb is not placed at _alt.

Setpos sould put the object at a given z (select 2) avobe the ground, but this is not happening!

Here is the script if you whant to take a look

`; Guided air attack by Viriato.`

; HEEEEEEEEEELP!

; What i am trying to do: If the bomb is created at the same relative heigth of a given target

; and the velocity added to the bomb is well calculated, the bomb will always hit the same spot ( the target)

; But this donÂ´t work and i donÂ´t know why!

_Target = _this select 0

; radio chatter and comunications here

eagle sidechat "Roger, heading for target"

~6

eagle sidechat "weapon fired"

~2

;create the bomb

_missil = "LaserGuidedBomb" CreateVehicle [(getpos _target select 0), (getpos _target select 1) -300, 1000]

; create a dummy object at the point where you whant to "launch" the bomb

_traker = "HeliHEmpty" CreateVehicle [(getpos _target select 0), (getpos _target select 1) -300, 0]

_traker setpos [(getpos _target select 0), (getpos _target select 1) -300, 0]

; Calculate the heigth above sea level of the target

lastrig setpos [(getpos _target select 0), (getpos _target select 1), 0]

_tarheigth = (getpos _target select 2) - (getpos lastrig select 2)

; calculate the heigth above sea level of the ground at the launching point

lastrig setpos [(getpos _traker select 0), (getpos _traker select 1), 0]

_trakheigth = (getpos _traker select 2) - (getpos lastrig select 2)

; Calculate the heigth diference between the target and the ground at the point where the bomb is launched

_dif = _tarheigth - _trakheigth

; Calculate the heigth above the ground of the bomb launching point

_alt = 150 + _dif

; Put the bomb at the launching point

_x = getpos _missil select 0

_y = getpos _missil select 1

_missil setpos [_x, _y, _alt]

; Add the bomb some velocity

_missil setvelocity [0,55,0]

; this is for testing porpouses, i whant to know whats going wrong

_misalt = getpos _missil select 2

eagle sidechat format ["Heigth of the bomb avobe the ground at launching point is %1",_misalt]

eagle sidechat format ["Heigth of the target ASL is %1",_tarheigth]

eagle sidechat format ["Heigth of the ground at the launching point ASL is %1",_trakheigth]

eagle sidechat format ["Heigth diferencce between the target and the ground at the launching point is %1",_dif]

eagle sidechat format ["Heigth above the ground where the bomb should be created should be %1",_alt]

~0.1

Deletevehicle _traker

?called >= maxcall :exit ; 1 setradiomsg "null" ; eagle sidechat "All weapons fired, good luck"

called = cal2pt

##### Share on other sites

Anybody?

I know that Dinger and Prospero had take a deep look insigth this subject.

##### Share on other sites

Are you sure the command _traker is valid? I believe Traker is spelled T-R-A-C-K-E-R... But what is the error you recieve when you try to run the script?

##### Share on other sites

I didnt studied your script deeply, but i remember a friend of mine having the same problem long ago.

Is the "dummy" placed up in the air also? if so it will also drop

Another thing, to calculate the relative position fast (and i mean really fast) you should get the function made by Joltan, acka as Dadlid, available at OFPEC or at his site

##### Share on other sites

sorry, didn't see this right away Viriato.

To tired to read it all the way through, but

try setting LasTrig only by x,y coordinates. E.g., LasTrig setpos [getpos whatever select 0, getpos whatever select 1]

that should keep the Z at the proper level.

If that fails, use a gamelogic. Here code I know works (comes from the targeting routine for CoC_UnifiedArtillery

_asset = origin

_aimpoint = target

CoCIFWidgetB = Gamelogic

_Zoffset = difference (+up, -down) from origin to target.

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">

_assetpos = getpos _asset;

_aimpointpos = getpos _aimpoint;

_distance = _asset distance _aimpoint;

_OriginX = _assetPos select 0;

_OriginY = _assetPos select 1;

_TargetX = _AimpointPos select 0;

_TargetY = _AimpointPOs select 1;

_XOffset = _TargetX - _OriginX;

_YOffset = _TargetY - _OriginY;

_Distance2D = sqrt((_XOffset^2) + (_Yoffset^2));

_ZOffset = sqrt ((_Distance ^2) - (_Distance2D^2));

if (format ["%1", _zOffset] == {-1.#IND}) then {_zOffset = 0};

CoCIFWidgetB setpos [_TargetX, _TargetY, _Zoffset];

if (_asset distance CoCIFWidgetB < _Distance) then {_ZOffset = -1 * _Zoffset};

<span id='postcolor'>

##### Share on other sites

Thank you very much Dinger, i'll make a try.

##### Share on other sites

Just seen this thread.

Accurate determination of absolute height is not as simple as it should be, but it has been addressed at considerable length. It's highly likely that a search on "absolute AND height" will provide you with what you need (providing I wrote what you end up reading).

Prospero