Here's something which stumped me for hours in my current scripts.
Issue: Stacked objects cause GetPos and GetPosASL to only return the relative height (select 2) above the current object (which can be positive or negative), not above ground or sea level, as I expected.
(If this is true, it needs to be added to BIKI getPos.)
The scenario: Now you wouldn't normally encounter this unless you double stack. I wanted to have my radio towers on top of buildings and then to have a danger sign on top of or near the towers, relative to the tower's position. I can't get the relative position.
Problem: Now it's very clever that GetPos does this, but for GetPosASL to do it is plain wrong. This causes problems because I still need a true height position of the object so I can vertically position objects relative to other objects. So if anyone knows of a command or way to do this, let me know.
-- EDIT: -- WORK-AROUND SOLUTION --
deanosbeano's solution works great:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Offset = [_x,_y,_z];
_worldPos = _RelObj modelToWorld _Offset;
_obj setPos _worldPos;[/QUOTE]
Note added to getPos - warning.
Note added to modelToWorld - usage.
-- END EDIT --
Screenshot of test scenario (with debug info in Hint)
InitTower.sqf - test script
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_Tower = _this select 0; // radio tower
_HgtOffset = _this select 1; // height pos adjustment of tower (above ground level)
//---- Position the tower on top of a building rooftop
// if the following line is used, then the 2nd setPos call somehow trieds to repos the object in the x & y directions onto a clear space on the ground
//_Tower setPos [ (getPos _Tower select 0), (getPos _Tower select 1), 0 ]; // don't want to use this, but try with or without this line for testing
// Towers placed on top of buildings require a height pos adjustment
_TowerHgtASL_Before = getPosASL _Tower select 2; // debug
_TowerHgtBefore = getPos _Tower select 2; // debug
_Tower setPos [ getPos _Tower select 0, getPos _Tower select 1, _HgtOffset ]; // try with or without this line for tests to see placement
// these 2 "After" values returned unexpected results, where z is now relative to top of building
_TowerHgtASL_After = getPosASL _Tower select 2; // debug
_TowerHgtAfter = getPos _Tower select 2; // debug
//---- Place a sign on top of tower - relative to the tower's current height
_sign = "Danger" createVehicle (position _Tower);
// x & y are roughly centre of tower, z hgt of 26.8 should be on top of tower
_x = (getPos _Tower select 0) + 0.1;
_y = (getPos _Tower select 1) + 1.9;
//_z = _TowerHgtAfter + 26.8 +_HgtOffset -12;
_z = _TowerHgtAfter + 26.9; // <- The idea here is that we don't know the original building height, so we want it relative to the tower's z height pos.
_sign setPos [ _x, _y, _z];
// this value returned unexpected result, where z is now relative to top of tower
_SignHgtAfter = getPos _sign select 2; // debug
//---- output stats of last Initialiazation
Hint Format["TowerName=%1 \n\nTowerHgtASL_Before=%2 \nTowerHgtASL_After=%3 \n\nTowerHgtBefore=%4 \nTowerHgtAfter=%5 \n\nSignHgtAfter=%6 \n_HgtOffset=%7",
VehicleVarName _Tower, _TowerHgtASL_Before, _TowerHgtASL_After, _TowerHgtBefore, _TowerHgtAfter, _SignHgtAfter, _HgtOffset ];
[/QUOTE]
mission.sqm - extract of 4 towers with their initialization
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> class Vehicles
{
items=4;
class Item0
{
position[]={10288.456055,146.113144,9210.3 29102};
id=2;
side="EMPTY";
vehicle="Land_vysilac_FM2";
skill=0.600000;
health=0.245674;
text="Tower2";
init="fn=compile preprocessFile ""InitTower.sqf""; [this, 18.12] call fn";
};
class Item1
{
position[]={10278.255859,142.778168,9210.3 06641};
id=3;
side="EMPTY";
vehicle="Land_vysilac_FM2";
skill=0.600000;
health=0.245674;
text="Tower3";
init="fn=compile preprocessFile ""InitTower.sqf""; [this, 12.5] call fn";
};
class Item2
{
position[]={10278.365234,127.979996,9198.4 22852};
id=4;
side="EMPTY";
vehicle="Land_vysilac_FM2";
skill=0.600000;
health=0.245674;
text="Tower4";
init="fn=compile preprocessFile ""InitTower.sqf""; [this, 0] call fn";
};
class Item3
{
position[]={10267.467773,142.778168,9210.2 45117};
id=1;
side="EMPTY";
vehicle="Land_vysilac_FM2";
skill=0.600000;
health=0.245674;
text="Tower1";
init="fn=compile preprocessFile ""InitTower.sqf""; [this, 12.12] call fn";
};
};
[/QUOTE]
Can someone confirm this? I definitely didn't expect GetPosASL to do this.
If this is all true, how does one get around it?
HOME
Reply With Quote


.
