Jump to content
tinter

Solution to getting and setting relative position and orientation of objects

Recommended Posts

If you have objects, like furniture in a building that you want to move to another building, you might run into problems with objects ending up being offset and being oriented weird. I've spent quite a while on this problem and with the help of a scripter named Nigel, we found the solution. For visibility I'm making a post here so anyone searching for it might stumble onto the solution.

tint_fnc_getRelPosAndOrientation = {
  param["_objA", "_objB"];
  _pos = getPosWorld _objA;
  if (!(surfaceIsWater _pos)) then {
    _pos = ASLToATL _pos;
  };
  _relativePos = _objB worldToModel _pos;
  _relativeOrientation = ([_objA, _objB] call BIS_fnc_vectorDirAndUpRelative);

  [_relativePos, _relativeOrientation]
};

tint_fnc_setRelPosAndOrientation = {
  param["_objA", "_objB", "_relPosAndOrientation"];
  _relPos = _relPosAndOrientation#0;
  _relOrientation = _relPosAndOrientation#1;
  _relDir = _relOrientation#0;
  _relUp = _relOrientation#1;
  
  _objA setVectorDirAndUp [_objB vectorModelToWorld _relDir, _objB vectorModelToWorld _relUp];
  _objA setPosWorld (_objB modelToWorldWorld _relPos);
};

I've made an issue about whether these functions would be a good fit for CBA, but it has stagnated https://github.com/CBATeam/CBA_A3/issues/1353

As a sidenote, if working specifically with houses, it might help to take the bounding center into account, since some houses that should be the same seem to have a slightly offset origin, you can see an example here https://github.com/Tinter/Tinter-Furniture/blob/master/furniture/functions/fn_dressUp.sqf#L62

  • Like 3

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

×