Jump to content
Sign in to follow this  
dr_eyeball

Stacked objects

Recommended Posts

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;

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 ];

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.329102};

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.306641};

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.422852};

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.245117};

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";

};

};

Can someone confirm this? I definitely didn't expect GetPosASL to do this.

If this is all true, how does one get around it?

Share this post


Link to post
Share on other sites

i personally use the worldtomodel or modeltoworld

the second of which will give you a better result.

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

_relPos = [_cm,0,_ht]

_worldPos = _founder modelToWorld _relPos

_brk setpos _worldPos

_cm and _ht are variables i use ,you can simply alter them with a number that you would like your sign offset from your tower.

appologies to the person who originallywrote this on biki i cant remember there name, but i addapted it and it helped me save 60 lines of code checkinng disatances.

like yousaid the original getpos is broke when it encounters a roof or any pathway because that wil return a _z of 0 wherever it is.

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

_relPos = [1,0,0]

_worldPos = _tower modelToWorld _relPos

_sign setpos _worldPos

try the above and play with numbers , also use it for your tower to (object ####) and radio tower

hope it helps

ps before the use of this neat command , the trick was to set the objects in editor and hint format the distance between the two, when everything was ok. then you would run a check of the distance after the objects where setpos`d , so if the distance should be hmm 10 , then you would ask ? distance sign < 9.8 then setpos x,y,_dist . where _dist would equal 10 in this case .

sory to confuse if i did.

Share this post


Link to post
Share on other sites

Thanks for confirming the issue with those commands.

The workaround looks good. I will try that.

Also, your final tip looks too sensible. What's wrong with previewing 10 times and incrementing by 1.0, 0.1 and 0.01 each time, until it's right? whistle.gif

Cheers.

Share this post


Link to post
Share on other sites
Quote[/b] ]What's wrong with previewing 10 times and incrementing by 1.0, 0.1 and 0.01 each time, until it's right?

lol i sense the irony somewhere :0.

the prob is that when you get it in the actual mission it will be sat on the ground again lol . thats why a 3 stage check ws always required wink_o.gif

cause it was a barstard.

and dont even get me started on arma buildings with stair case lol

there just as abs every step seems to reset _z to 0 .

lol

Share this post


Link to post
Share on other sites
Quote[/b] ]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.

Thats actualy a problem with roadway LOD's. They were a real pain in the a%^e with OFP to. It's a shame the above seal level version doesn't ignore them, I think someones already requested such a command that does, on the wiki?

Quote[/b] ]i personally use the worldtomodel or modeltoworld the second of which will give you a better result.

Will that ignore or compensate for roadway LOD's? You still have to use setpos, after all. Would be handy if it did.

Share this post


Link to post
Share on other sites

yup it does smile_o.gif.

unless i have been exremely lucky. have not had a fail yet.

and if it does i would just use the old distance check and change the third value of _relpos to the _dist.

i will try and find the original thread on this .

i was hoping maybe now your involved unn you might do two little pargagraphs

on worldtomodel and modeltoworld ??

maybe huh ??

my own brief thinking is it kakes the exact postion as it would be in the mission sqsm and converts that to a normal z,y,z as we would use in editor ,if that make sense

Share this post


Link to post
Share on other sites
Quote[/b] ] was hoping maybe now your involved unn you might do two little pargagraphs

on worldtomodel and modeltoworld ??

I can't really test anything ATM. But I will certainly give it a try over the weekend. I can see where your comming from, it would help with tide height problems too.

Share this post


Link to post
Share on other sites

If you still need a workaround for ASL and height above ground that defeats roadway LODs, here's what I used in my grenade pack scripts:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_detector = "EmptyDetector" camcreate [0,0,0]

_pos = (getpos _obj)

_detector setpos [_pos select 0,_pos select 1]

_asl = (_obj distance _detector)

_h = (_obj distance _detector)-(abs(getpos _detector select 2))

It should still work, if EmptyDetector still exists in ArmA. You could probably even turn them into functions:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private["_obj","_d","_pos","_z","_asl"];

_obj = _this;

_d = "EmptyDetector" camcreate [0,0,0];

_pos = (getpos _obj);

_d setpos [_pos select 0,_pos select 1];

_z = (_obj distance _d);

_asl = [_pos select 0,_pos select 1,_z];

deletevehicle _d;

_asl

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">private["_obj","_d","_pos","_z","_agl"];

_obj = _this;

_d = "EmptyDetector" camcreate [0,0,0];

_pos = (getpos _obj);

_d setpos [_pos select 0,_pos select 1];

_z = (_obj distance _d)-(abs(getpos _d select 2));

_agl = [_pos select 0,_pos select 1,_z];

deletevehicle _d;

_agl

Share this post


Link to post
Share on other sites
Quote[/b] ]If you still need a workaround for ASL and height above ground that defeats roadway LODs, here's what I used in my grenade pack scripts:

deanosbeano suggestion means we don't have to worry about using detectors or logics anymore. Using modelToWorld you can now get the position with just one command:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">Player ModelToWorld [0,0,0]

I did a quick test, that will now return the correct height when stood on a elevated roadway. But it still appards to be effect by the height of the tide, if your over water when you call the command.

To identify when an object is over an elevated roadway, you could probably use this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">((Player ModelToWorld [0,0,0]) Select 2)!=((GetPos Player) Select 2)

There are still other issues with roadways, but it at least cuts out some of the lengthy work arounds.

@Dr_Eyeball

Another possible solution, if your doing this for a SP mission. Is to use camCreate. In OFP cam created objects were not influenced by roadways, as far as I can remember. So you should be able to stack your objects using multipliers of thier height. Assuming it works the same way in Arma.

Share this post


Link to post
Share on other sites

Hmmm

ok i ask in all sincerity ,is it not the case that you cannot camcreate any objects anymore ?

or is it specific objects ?

if you can still camcreate then i have dropped some major bollocks in the last week or so lol.

Share this post


Link to post
Share on other sites

I haven't seen anything in the Wiki to say otherwise? It's still listed under Arma scripting.

Share this post


Link to post
Share on other sites

please forgive me but the wiki is something i have avoided over last few weeks, i had some terrible experience with that code posted there and almost lost a 200 gig hard drive becuase of 5 ctd and some blue screens i believe when it first became available some fanboys did a copy and paste job and was not aware of the consequences. but i see some very good website chaps there now so hopefully it will soon be hive of good qality info

.

i was told on icq that camcreate is now replaced by createvehicle local and simple createvehicle( apparently now more satvle for mp).

i just tried to camcreate and its true it dosent work anymore ,hmmm more and more porting lol.

Share this post


Link to post
Share on other sites

I can also confirm that issue,

i ran into it while trying to find the absolute height of a camera

because there is no camsetposASL command.

But always when the camera is above an object the camera would bounce up by the height of that object.

I will try it with modelToWorld, seems promising.

Good workaround idea there deanosbeano!

Edit: modelToWorld isn't needed for the specific problem that i had,

i just forgot to actually setpos the object that measures the absolute ground height after createvehicle-ing

it,setpos compensated for the height differences that i had before.

Still the modelToWorld-workaround will find its applications.

Share this post


Link to post
Share on other sites

no mention of any ammendmant to the command in 1.04 too sad_o.gif

looks like we ait for 1.05 and see.

nice job on adding to bugtracker tho bdfy

Share this post


Link to post
Share on other sites

--snip--

crap. am i on drugs? what am i saying? i mean: i found a workarround. the distance operator works on this.

_obj_nullPoint = "Misc01" createVehicle[ 0,0,0 ];

_obj_nullPoint setPos[ ( getPos _this )select 0,getPos _this select 1,0 ];

_float_posZ = _this distance _obj_nullPoint;

deleteVehicle _obj_nullPoint;

works

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  

×