{"name":"vectorMultiply","title":"vectorMultiply","type":"command","url":"https://community.bistudio.com/wiki/vectorMultiply","revid":373016,"updated":"2025-03-18T15:24:19Z","groups":["Math - Vectors"],"status":"ok","games":{"arma3":"1.22"},"since":"arma3 1.22","arma3_since":"1.22","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> 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","params":[{"name":"numArray","type":"Array of Numbers","description":"an array of any size to be multiplied with the multiplier","type_expr":"Array<Number>"},{"name":"multiplier","type":"Number or Arma 3 v2.14 Array of Numbers","type_expr":"Number | Array<Number>"}],"returns":{"type":"Array of Numbers","type_expr":"Array<Number>"},"form":"binary","left":{"text":"numArray"},"right":{"text":"multiplier"}}],"examples":[{"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\"];"]}],"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```"}]}