{"name":"vectorMultiply","operator":null,"title":"vectorMultiply","type":"command","url":"https://community.bistudio.com/wiki/vectorMultiply","revid":373016,"updated":"2025-03-18T15:24:19Z","groups":["Math - Vectors"],"status":"ok","replaced_by":[],"games":[{"game":"arma3","name":"Arma 3","version":"1.22"}],"since":{"game":"arma3","name":"Arma 3","version":"1.22"},"arma3_since":"1.22","branch":null,"locality":{"argument":null,"effect":null,"server_exec":false},"exec":null,"description":"Multiplies an array of numbers by a scalar or another array of numbers.\n\n> [!NOTE]\n> **Since Arma 3 v2.14:** Since Arma 3 v2.14 any count of numbers is valid, if one array is larger than the other, the remaining elements are inserted without change.\n>\n> Before Arma 3 v2.14, the first argument had to be vector 3D, or Arma 3 v2.00 2D (Which still returned 3D result, with z coordinate defaulted to 0)","syntaxes":[{"syntax":"numArray vectorMultiply multiplier","since":null,"effect":null,"exec":null,"params":[{"name":"numArray","type":"Array of Numbers","optional":false,"default":null,"description":"an array of any size to be multiplied with the multiplier","types":["Array","Number"],"since":null,"text":"numArray: Array of Numbers - an array of any size to be multiplied with the multiplier"},{"name":"multiplier","type":"Number or Arma 3 v2.14 Array of Numbers","optional":false,"default":null,"description":null,"types":["Number","Array"],"since":null,"text":"multiplier: Number or Arma 3 v2.14 Array of Numbers"}],"returns":{"type":"Array of Numbers","types":["Array","Number"],"description":null,"text":"Array of Numbers"},"form":"binary","operator":null,"left":{"text":"numArray","types":["Array","Number"]},"right":{"text":"multiplier","types":["Number","Array"]}}],"examples":[{"text":"```sqf\n_newVector = [1,2,3] vectorMultiply 3; // returns [3,6,9]\n```","code":["_newVector = [1,2,3] vectorMultiply 3; // returns [3,6,9]"]},{"text":"```sqf\n[1,2,3,4] vectorMultiply [1,2,3,4];    // [1,4,9,16]\n[1,2,3,4] vectorMultiply 2;            // [2,4,6,8]\n[1,2,3,4] vectorMultiply [2];        // [2,2,3,4]\n[2] vectorMultiply [1,2,3,4];        // [2,2,3,4]\n[1,2,3] vectorMultiply [1,2,3,4,5];    // [1,4,9,4,5]\n```","code":["[1,2,3,4] vectorMultiply [1,2,3,4];\t// [1,4,9,16]\n[1,2,3,4] vectorMultiply 2;\t\t\t// [2,4,6,8]\n[1,2,3,4] vectorMultiply [2];\t\t// [2,2,3,4]\n[2] vectorMultiply [1,2,3,4];\t\t// [2,2,3,4]\n[1,2,3] vectorMultiply [1,2,3,4,5];\t// [1,4,9,4,5]"]},{"text":"```sqf\nprivate _eyePos = eyePos player;\nprivate _eyeDir = getCameraViewDirection player;    // this is a normalized vector, i.e. its magnitude is 1\nprivate _100mFurther = _eyeDir vectorMultiply 100;    // since _eyeDir is normalised (length = 1m), multiplying it by 100 means 100m in that direction\nprivate _lookPos = _eyePos vectorAdd _100mFurther;    // the position where player is looking 100m ahead\n```","code":["private _eyePos = eyePos player;\nprivate _eyeDir = getCameraViewDirection player;\t// this is a normalized vector, i.e. its magnitude is 1\nprivate _100mFurther = _eyeDir vectorMultiply 100;\t// since _eyeDir is normalised (length = 1m), multiplying it by 100 means 100m in that direction\nprivate _lookPos = _eyePos vectorAdd _100mFurther;\t// the position where player is looking 100m ahead"]},{"text":"```sqf\n// Override firing to throw the player towards where he's aiming\nplayer allowDamage false;\nplayer addAction [\"\", {\n    player setVelocity ((player weaponDirection \"\") vectorMultiply 20);\n}, \"\", 0, false, true, \"DefaultAction\"];\n```","code":["// Override firing to throw the player towards where he's aiming\nplayer allowDamage false;\nplayer addAction [\"\", {\n\tplayer setVelocity ((player weaponDirection \"\") vectorMultiply 20);\n}, \"\", 0, false, true, \"DefaultAction\"];"]}],"multiplayer":null,"problems":null,"aliases":[],"see_also":["vectorAdd","vectorDiff","vectorCrossProduct","vectorDotProduct","vectorMagnitude","matrixMultiply"],"notes":[{"user":"ffur2007slx2_5","date":"2014-06-28T08:21:00Z","text":"Arma 3 v1.22 Algorithm:\n\n```sqf\nVector = [x, y, z]; scalar = a;\nResult = [(x * a), (y * a), (z * a)];\n```\n\nIt is recommended to use vectorMultiply instead of BIS_fnc_vectorMultiply.\nThis is a very useful function, as it can be used with the velocity command to move an object from one position to another. (ie <vector1> to <vector2>) - ensure both positions are found using getPosASL.\n\n```sqf\n_obj setVelocity (((getPosASL _target) vectorDiff (getPosASL _obj)) vectorMultiply 2);\n```"}],"categories":["Arma 3: New Scripting Commands","Arma 3: Scripting Commands","Command Group: Math - Vectors","Introduced with Arma 3 version 1.22","Scripting Commands"]}