{"name":"selectionVectorDirAndUp","operator":null,"title":"selectionVectorDirAndUp","type":"command","url":"https://community.bistudio.com/wiki/selectionVectorDirAndUp","revid":377722,"updated":"2026-01-02T09:17:58Z","groups":["Object Manipulation"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"2.06"}],"since":{"game":"arma3","name":"Arma 3","version":"2.06"},"arma3_since":"2.06","branch":null,"locality":{"argument":"global","effect":null,"server_exec":false},"exec":null,"description":"Searches for selection in the object model's LOD level, and returns the Direction and Up vectors in model space.","syntaxes":[{"syntax":"object selectionVectorDirAndUp [selectionName, LOD]","since":null,"effect":null,"exec":null,"params":[{"name":"object","type":"Object","optional":false,"default":null,"description":null,"types":["Object"],"since":null,"text":"object: Object"},{"name":"selectionName","type":"String","optional":false,"default":null,"description":"selection name (see selectionNames)","types":["String"],"since":null,"text":"selectionName: String - selection name (see selectionNames)"},{"name":"LOD","type":"String or Number","optional":false,"default":null,"description":"the LOD that contains the selection:\n- String - can be one of:\n  - \"Memory\"\n  - \"Geometry\"\n  - \"FireGeometry\"\n  - \"LandContact\"\n  - \"HitPoints\"\n  - \"ViewGeometry\"\n- Number - command searches for a LOD with the similar resolution (see allLODs).","types":["String","Number"],"since":null,"text":"LOD: String or Number - the LOD that contains the selection:\n- String - can be one of:\n  - \"Memory\"\n  - \"Geometry\"\n  - \"FireGeometry\"\n  - \"LandContact\"\n  - \"HitPoints\"\n  - \"ViewGeometry\"\n- Number - command searches for a LOD with the similar resolution (see allLODs)."}],"returns":{"type":"Array with [vectorDir, vectorUp]","types":["Array","vectorDir","vectorUp"],"description":"vectors are in model space - vectorDir: Vector3D - vectorUp: Vector3D","text":"Array with [vectorDir, vectorUp] - vectors are in model space\n- vectorDir: Vector3D\n- vectorUp: Vector3D"},"form":"binary","operator":null,"left":{"text":"object","types":["Object"]},"right":{"text":"[selectionName, LOD]","types":["Array"]}}],"examples":[{"text":"```sqf\nvehicle player selectionVectorDirAndUp [\"drivewheel_axis\", \"FireGeometry\"] params [\"_axisVectorDir\", \"_axisVectorUp\"];\n```","code":["vehicle player selectionVectorDirAndUp [\"drivewheel_axis\", \"FireGeometry\"] params [\"_axisVectorDir\", \"_axisVectorUp\"];"]},{"text":"Get the player's barrel end (`_p1` being muzzle end's ASL position):\n\n```sqf\nonEachFrame {\n    private _weapon = currentWeapon player;\n    if (_weapon == \"\") exitWith {};\n\n    // update weapon info upon weapon switch\n    if (_weapon != player getVariable [\"last_weapon\", \"?\"]) then\n    {\n        private _cfg = configFile >> \"CfgWeapons\" >> _weapon;\n        private _model = getText(_cfg >> \"model\");\n        private _simpleObject = createSimpleObject [_model, [0,0,0], true];\n        private _offset = _simpleObject selectionPosition [getText (_cfg >> \"muzzlePos\"), \"memory\"];\n        _offset = _offset apply { [_x] };\n        deleteVehicle _simpleObject;\n        player setVariable [\"offset\", _offset];\n        player setVariable [\"last_weapon\", _weapon];\n        player setVariable [\"proxy\",\n            [\n                \"proxy:\\a3\\characters_f\\proxies\\pistol.001\",\n                \"proxy:\\a3\\characters_f\\proxies\\weapon.001\",\n                \"proxy:\\a3\\characters_f\\proxies\\launcher.001\",\n                \"proxy:\\a3\\characters_f\\proxies\\binoculars.001\"\n            ] select (([1, 4, 4096] find getNumber (_cfg >> \"type\")) + 1)\n        ];\n    };\n\n    _offset = player getVariable [\"offset\", []];\n    private _proxy = player getVariable [\"proxy\", \"\"];\n    // using LOD resolution 1 (and lod index 0) - this is not always reliable\n    // you should manually check allLODs and find the most suitable LOD (smallest res LOD usually has the best accuracy, but it might be slow too)\n    player selectionVectorDirAndUp [_proxy, 1] params [\"_vy\", \"_vz\"];\n    private _pos = selectionPosition [player, _proxy, 0];\n    private _vx = _vy vectorCrossProduct _vz;\n\n    private _mat = matrixTranspose [_vx, _vy, _vz];\n    _pos = _pos vectorAdd flatten (_mat matrixMultiply _offset);\n\n    private _p1 = player modelToWorldVisualWorld _pos;\n    private _p2 = _p1 vectorAdd (player vectorModelToWorldVisual (_vx vectorMultiply -1000));\n    drawLine3D [ASLToAGL _p1, ASLToAGL _p2, [1,0,0,1]];\n};\n```","code":["onEachFrame {\n\tprivate _weapon = currentWeapon player;\n\tif (_weapon == \"\") exitWith {};\n\n\t// update weapon info upon weapon switch\n\tif (_weapon != player getVariable [\"last_weapon\", \"?\"]) then\n\t{\n\t\tprivate _cfg = configFile >> \"CfgWeapons\" >> _weapon;\n\t\tprivate _model = getText(_cfg >> \"model\");\n\t\tprivate _simpleObject = createSimpleObject [_model, [0,0,0], true];\n\t\tprivate _offset = _simpleObject selectionPosition [getText (_cfg >> \"muzzlePos\"), \"memory\"];\n\t\t_offset = _offset apply { [_x] };\n\t\tdeleteVehicle _simpleObject;\n\t\tplayer setVariable [\"offset\", _offset];\n\t\tplayer setVariable [\"last_weapon\", _weapon];\n\t\tplayer setVariable [\"proxy\",\n\t\t\t[\n\t\t\t\t\"proxy:\\a3\\characters_f\\proxies\\pistol.001\",\n\t\t\t\t\"proxy:\\a3\\characters_f\\proxies\\weapon.001\",\n\t\t\t\t\"proxy:\\a3\\characters_f\\proxies\\launcher.001\",\n\t\t\t\t\"proxy:\\a3\\characters_f\\proxies\\binoculars.001\"\n\t\t\t] select (([1, 4, 4096] find getNumber (_cfg >> \"type\")) + 1)\n\t\t];\n\t};\n\n\t_offset = player getVariable [\"offset\", []];\n\tprivate _proxy = player getVariable [\"proxy\", \"\"];\n\t// using LOD resolution 1 (and lod index 0) - this is not always reliable\n\t// you should manually check allLODs and find the most suitable LOD (smallest res LOD usually has the best accuracy, but it might be slow too)\n\tplayer selectionVectorDirAndUp [_proxy, 1] params [\"_vy\", \"_vz\"];\n\tprivate _pos = selectionPosition [player, _proxy, 0];\n\tprivate _vx = _vy vectorCrossProduct _vz;\n\n\tprivate _mat = matrixTranspose [_vx, _vy, _vz];\n\t_pos = _pos vectorAdd flatten (_mat matrixMultiply _offset);\n\n\tprivate _p1 = player modelToWorldVisualWorld _pos;\n\tprivate _p2 = _p1 vectorAdd (player vectorModelToWorldVisual (_vx vectorMultiply -1000));\n\tdrawLine3D [ASLToAGL _p1, ASLToAGL _p2, [1,0,0,1]];\n};"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["selectionPosition","selectionNames","allLODs"],"notes":[],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Object Manipulation","Introduced with Arma 3 version 2.06","Scripting Commands"]}