{"name":"setVectorDirAndUp","operator":null,"title":"setVectorDirAndUp","type":"command","url":"https://community.bistudio.com/wiki/setVectorDirAndUp","revid":378407,"updated":"2026-04-04T08:14:53Z","groups":["Math - Vectors"],"status":"ok","replaced_by":[],"games":[{"game":"arma1","name":"Armed Assault","version":"1.09"},{"game":"arma2","name":"Arma 2","version":"1.00"},{"game":"arma2oa","name":"Arma 2: Operation Arrowhead","version":"1.50"},{"game":"tkoh","name":"Take On Helicopters","version":"1.00"},{"game":"arma3","name":"Arma 3","version":"0.50"}],"since":{"game":"arma1","name":"Armed Assault","version":"1.09"},"arma3_since":"0.50","branch":null,"locality":{"argument":"local","effect":"global","server_exec":false},"exec":null,"description":"Sets orientation of an object.\nThe command takes 2 vector arrays, one for vectorDir and one for vectorUp.\nDefault object orientation will always have vectorDir pointing forward (North) along Y axis and vectorUp pointing up along Z axis - [[0,1,0],[0,0,1]], as shown on the diagram below (see also BIS_fnc_transformVectorDirAndUp).\n\nWhen attaching object to an object the axes are relative to the object that gets the attachment.\nIf it is player object for example, then X goes from left to right, Y goes from back to front, and Z goes from down up.\n\nThe setDir command is incompatible with setVectorDirAndUp and should not be used together on the same object.\nUsing setVectorDirAndUp alone should be sufficient for any orientation.","syntaxes":[{"syntax":"vehicle setVectorDirAndUp [vectorDir, vectorUp]","since":null,"effect":null,"exec":null,"params":[{"name":"vehicle","type":"Object","optional":false,"default":null,"description":null,"types":["Object"],"since":null,"text":"vehicle: Object"},{"name":"vectorDir","type":"Vector3D","optional":false,"default":null,"description":"vectorDir","types":["Vector3D"],"since":null,"text":"vectorDir: Vector3D - vectorDir"},{"name":"vectorUp","type":"Vector3D","optional":false,"default":null,"description":"vectorUp","types":["Vector3D"],"since":null,"text":"vectorUp: Vector3D - vectorUp"}],"returns":{"type":"Nothing","types":["Nothing"],"description":null,"text":"Nothing"},"form":"binary","operator":null,"left":{"text":"vehicle","types":["Object"]},"right":{"text":"[vectorDir, vectorUp]","types":["Array"]}}],"examples":[{"text":"```sqf\n// set exact yaw, pitch, and roll\n_yaw = 45; _pitch = -80; _roll = 0;\n_myObject setVectorDirAndUp [\n    [sin _yaw * cos _pitch, cos _yaw * cos _pitch, sin _pitch],\n    [[sin _roll, -sin _pitch, cos _roll * cos _pitch], -_yaw] call BIS_fnc_rotateVector2D\n];\n```","code":["// set exact yaw, pitch, and roll\n_yaw = 45; _pitch = -80; _roll = 0;\n_myObject setVectorDirAndUp [\n\t[sin _yaw * cos _pitch, cos _yaw * cos _pitch, sin _pitch],\n\t[[sin _roll, -sin _pitch, cos _roll * cos _pitch], -_yaw] call BIS_fnc_rotateVector2D\n];"]},{"text":"To rotate _myObject on Z axis 90 degrees clockwise, change its vectorDir but leave vectorUp unchanged.\n\n```sqf\n_myObject setVectorDirAndUp [[1,0,0], [0,0,1]];\n```","code":["_myObject setVectorDirAndUp [[1,0,0], [0,0,1]];"]},{"text":"To rotate _myObject on Y axis 90 degrees clockwise, change its vectorUp but leave vectorDir unchanged.\n\n```sqf\n_myObject setVectorDirAndUp [[0,1,0], [1,0,0]];\n```","code":["_myObject setVectorDirAndUp [[0,1,0], [1,0,0]];"]},{"text":"To rotate _myObject on X axis 90 degrees (tilt forward), change both vectorDir and vectorUp accordingly.\n\n```sqf\n_myObject setVectorDirAndUp [[0,0,-1], [0,1,0]];\n```","code":["_myObject setVectorDirAndUp [[0,0,-1], [0,1,0]];"]},{"text":"More complex orientations\n\n```sqf\n// tilt forward 90 + rotate left 90\n_myObject setVectorDirAndUp [[1,0,0], [0,1,0]];\n// tilt backward 45 degrees\n_myObject setVectorDirAndUp [[0,0.5,0.5], [0,-0.5,0.5]];\n// tilt forward 30 degrees\n_myObject setVectorDirAndUp [[0,0.66,-0.33], [0,0.33,0.66]];\n```","code":["// tilt forward 90 + rotate left 90\n_myObject setVectorDirAndUp [[1,0,0], [0,1,0]];\n// tilt backward 45 degrees\n_myObject setVectorDirAndUp [[0,0.5,0.5], [0,-0.5,0.5]];\n// tilt forward 30 degrees\n_myObject setVectorDirAndUp [[0,0.66,-0.33], [0,0.33,0.66]];"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["vectorDir","vectorUp","setVectorDir","setVectorUp","vectorDiff","vectorAdd","vectorMultiply","vectorCrossProduct","vectorDistance","vectorMagnitudeSqr","vectorDistanceSqr","vectorCos","vectorMagnitude","vectorDotProduct","vectorNormalized","vectorFromTo","BIS_fnc_transformVectorDirAndUp"],"notes":[{"user":"Str","date":"2008-03-16T09:50:00Z","text":"Command can be also used to rotate camera in all three axis (which also mean it is possible to set camera bank)."},{"user":"General Barron","date":"2008-05-09T09:32:00Z","text":"The object's vectorDir can only control its pitch, while its vectorUp can only control its bank. To set an object's yaw (direction), use the setdir command, before using this command.\nYou would think vectorUp would control pitch as well, but any pitch that would be set due to vectorUp is ignored. The same is true with vectorDir and yaw; any vectorDir that would adjust yaw is also ignored. If this doesn't make sense, try to visualize it with a box or soda can.\nThis command does NOT work with values relative to a unit, but rather it works with world vectors (think world coordinates as opposed to model coordinates). As a result, this command can be difficult to use in many situations, because the input values needed to get a certain pitch / bank for an object vary, depending on what direction the object is facing (yaw).\nA function to set an object's pitch / bank can be found"},{"user":"Chris330","date":"2009-10-23T18:39:00Z","text":"Note this odd command may now be better understood. There's a thread about it here:"},{"user":"ffur2007slx2_5","date":"2014-06-01T18:45:00Z","text":"Arma 3 v1.20 setDir overwrites setVectorDirAndUp (P.S. setVectorDirAndUp also affects setVelocity.), so use setDir before BIS_fnc_setPitchBank, which is an easier workaround on vector, if changing yaw, pitch and bank are needed. setVectorDirAndUp is CCW, so if we wanna to set an obj 40 degrees CW, 170 degrees pitch and 85 degrees bank:\n\n```sqf\n_obj setDir (40 - 180); [_obj, 170, 85] call BIS_fnc_setPitchBank;\n```\n\nSame as:\n\n```sqf\n_obj setVectorDirAndUp [[0.63,0.75,0.17],[-0.75,0.65,-0.084]];\n```\n\nBe aware that attachTo may flip vectorDir if pitch beyond 90 degrees and cause unexpected behavior to BIS_fnc_setPitchBank, e.g.\n\n```sqf\n[_obj, 100, 0] call BIS_fnc_setPitchBank; // vector: [-0.14,-0.09,0.98],[-0.83,-0.51,-0.17]\n```\n\n```sqf\n_obj attachTo [_logic,[0,0,2]];\n[_obj, 100, 0] call BIS_fnc_setPitchBank; // vector: [0.11,0.33,0.93],[-0.06,0.94,-0.32]\n```\n\ncompass direction algorithm failed if obj was attached at present.\nTo overcome such limitation we can use fallowing function for a better workaround. (code originated from '''bapedibupa'', remodified)\n\n```sqf\n_obj attachTo [_logic,[0,0,2]];\n[_obj,[120,-78,37]] call fnc_SetPitchBankYaw; // pitch: 120, bank: -78, yaw: 37\n```\n\n```sqf\nfnc_SetPitchBankYaw = {\n    private [\"_object\", \"_rotations\", \"_aroundX\", \"_aroundY\", \"_aroundZ\", \"_dirX\", \"_dirY\",\n    \"_dirZ\", \"_upX\", \"_upY\", \"_upZ\", \"_dir\", \"_up\", \"_dirXTemp\", \"_upXTemp\"];\n    _object = _this select 0;\n    _rotations = _this select 1;\n    _aroundX = _rotations select 0;\n    _aroundY = _rotations select 1;\n    _aroundZ = (360 - (_rotations select 2)) - 360;\n    _dirX = 0;\n    _dirY = 1;\n    _dirZ = 0;\n    _upX = 0;\n    _upY = 0;\n    _upZ = 1;\n    if (_aroundX != 0) then {\n        _dirY = cos _aroundX;\n        _dirZ = sin _aroundX;\n        _upY = -sin _aroundX;\n        _upZ = cos _aroundX;\n    };\n    if (_aroundY != 0) then {\n        _dirX = _dirZ * sin _aroundY;\n        _dirZ = _dirZ * cos _aroundY;\n        _upX = _upZ * sin _aroundY;\n        _upZ = _upZ * cos _aroundY;\n    };\n    if (_aroundZ != 0) then {\n        _dirXTemp = _dirX;\n        _dirX = (_dirXTemp* cos _aroundZ) - (_dirY * sin _aroundZ);\n        _dirY = (_dirY * cos _aroundZ) + (_dirXTemp * sin _aroundZ);\n        _upXTemp = _upX;\n        _upX = (_upXTemp * cos _aroundZ) - (_upY * sin _aroundZ);\n        _upY = (_upY * cos _aroundZ) + (_upXTemp * sin _aroundZ);\n    };\n    _dir = [_dirX,_dirY,_dirZ];\n    _up = [_upX,_upY,_upZ];\n    _object setVectorDirAndUp [_dir,_up];\n};\n```"}],"categories":["ArmA: Armed Assault: New Scripting Commands","ArmA: Armed Assault: Scripting Commands","Arma 2: Operation Arrowhead: Scripting Commands","Arma 2: Scripting Commands","Arma 3: Scripting Commands","Command Group: Math - Vectors","Introduced with Armed Assault version 1.09","Scripting Commands","Scripting Commands: Global Effect","Take On Helicopters: Scripting Commands"]}