Jump to content
Sign in to follow this  
celery

setPos height snap to non-terrain surface

Recommended Posts

While thinking of ways to dodge honest work in object placement I got an idea how to remove manual setPos tinkering. The script "snaps" an object to the highest non-terrain surface below it by deducting the regular setPos value (that counts roofs and such as the zero point) from setPosASL (height above sea level). It means that your height micromanagement drops by at least 80% (or your money back!), leaving you only to check for possible offset or readjust the floor height for indoor jobs. This script is especially useful on the carrier ship.

It works on pretty much all structures save for hangars and the edges of some roofs.

Below is an illustration of the script's effect with the shown objects simply having executed the script.

a2snapheight.jpg

Script with instructions:

;Snap altitude script for objects written by Celery
;
;Put [this,0,0] exec "snapheight.sqs" into an object's init line to make
;it "snap" to the highest non-terrain surface without micromanagement.
;
;To make it work indoors on a level of your choosing, replace the
;first 0 with the approximate height of the desired level and the
;object will snap to the nearest level below that height.
;
;In case of slight offset in the height after executing the script
;you can replace the second 0 with a trim value that increases or
;decreases the object's final height.
;
;Init line "lite" version:
;this setPosASL [getPos this select 0,getPos this select 1,10000];this setPosASL [getPos this select 0,getPos this select 1,(getPosASL this select 2)-(getPos this select 2)]

?!isServer:exit

_object=_this select 0
_indoorsheight=_this select 1
_trim=_this select 2

?_indoorsheight==0:_indoorsheight=10000
?getPosASL _object select 2>getPosATL _object select 2:_indoorsheight=(getPosASL _object select 2)+_indoorsheight

_object setPosASL [getPos _object select 0,getPos _object select 1,_indoorsheight]
_object setPosASL [getPos _object select 0,getPos _object select 1,(getPosASL _object select 2)-(getPos _object select 2)+_trim]

exit

In the test mission you can see all the examples of the script's usage both at the airport and on the carrier. As the instructions say, if you want the basic effect without a script, put this in the object's init line:

this setPosASL [getPos this select 0,getPos this select 1,10000];this setPosASL [getPos this select 0,getPos this select 1,(getPosASL this select 2)-(getPos this select 2)]

The highlighted number can be changed to snap the object indoors.

>>>Download the test mission<<<

Happy object placing. ;)

Edited by Celery

Share this post


Link to post
Share on other sites

As long as it's not some buggy object that bounces when setPos too close to the deck, can't you just setPosASL it once to some random height, let it fall down to the deck and then getPosASL it to get the correct height to set it to next time?

Share this post


Link to post
Share on other sites
As long as it's not some buggy object that bounces when setPos too close to the deck, can't you just setPosASL it once to some random height, let it fall down to the deck and then getPosASL it to get the correct height to set it to next time?

That's one of the chores this script eliminates. Also, many objects have no physics so they can't fall down.

Share this post


Link to post
Share on other sites

You can probably use another object that can fall though and then use its height.

I thought the chore you were trying to eliminate is one needing to repeatedly adjust the height until a correct one is achieved? My solution only requires you to preview the mission once.

Share this post


Link to post
Share on other sites
You can probably use another object that can fall though and then use its height.

I thought the chore you were trying to eliminate is one needing to repeatedly adjust the height until a correct one is achieved? My solution only requires you to preview the mission once.

If you look at the init line piece, you can see that this is as simple as it gets. No hint formats, no writing and no repeated previews to make it right, just paste the line and you have it.

Share this post


Link to post
Share on other sites

Superb Celery, this saves SOOO much work doing getpos and setpos statements etc. Legendary!

Share this post


Link to post
Share on other sites

You still have to preview to get the x and y correct. So, could just do a repeatedly radio trigger

copytoclipboard str (getposasl player)

then just

this setposasl *paste*

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  

×