Jump to content
Sign in to follow this  
tinter

getPos Relative To Objects Underneath

Recommended Posts

I want to place units on top of a building, but rather than manually get the height of buildings and figuring out which one I'm placing the unit on, I'd like to know if there's a way to get the position of an object counting what's underneath it. So if I first setPos an object to 100 and it happens to be above a building, then I want to get the altitude of the object relative to the building, instead of above the ground.

---------- Post added at 23:10 ---------- Previous post was at 22:35 ----------

Fixed it myself. It turns out there's a small mismatch in getPos and setPos, in that getPos will return the height above things below it, like I want to, but setPos sets the position relative to the ground. But by subtracting getPosATL by getPos, I get the height I need.

This code works fine in the init line of a unit and gives me what I need.

null = [this] spawn {_obj = _this select 0; _obj setPos [getPos _obj select 0, getPos _obj select 1, 50]; sleep 1; _height = (getPosATL _obj select 2) - (getPos _obj select 2); _obj setVelocity [0,0,0]; _obj setPos [getPos _obj select 0, getPos _obj select 1, _height]}

---------- Post added at 23:11 ---------- Previous post was at 23:10 ----------

Sleep is not needed and is just there for debugging purposes.

  • Thanks 1

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  

×