Results 1 to 2 of 2

04012012, 05:19 PM #1
[EDITING] Checking a units speed using speed vectors
Though arma knows speed to return a unit's movement speed, this unfortunately only returns km/h, making it incomparable to getSpeed which returns units per second.
So if we wanted to check if a unit is moving at a certain speed and then want something to happen we have to use velocity.:
In the example, a unit sets off a trigger that activates nul=[thisList] execVM "speedcheck.sqf"Code:_unit = _this select 0; _speed = sqrt ( (velocity _unit select 0)^2 + (velocity _unit select 1)^2 + (velocity _unit select 2)^2 ); //triangulation reduces the array velocity returns to a single number _allowedSpeed = (_unit getSpeed "Normal"); //we define the allowed movement speed (for infantry "Normal" is a jog at 4.0) if (_speed > _allowedSpeed) then { _running = 1; //the unit is running } else { _running = 0; //the unit is going slower than jogging}; if (f_var_debugMode == 1) then { //using the default F2 Debug parameter player sidechat format ["_speed:%1,_allowedspeed=%2", _speed, _allowedspeed]; player sidechat format ["running:%1",_running];};
Thanks to Nullkigan for coming up with the codestuff.Last edited by Wolfenswan; 05012012 at 12:20 AM.

04012012, 06:19 PM #2
Not sure that will work because "this" in activation will return false, not a unit as you want.
Here's an example I whipped up for velocity sensitve IEDs:
Originally Posted by Trigger
The script then looks like this (I doubled up on isServer, but it pays to be careful with locality):
Code:private ["_unit","_speed","_allowedSpeed","_trigger","_ammotype","_chance","_variance","_variancey","_rand"]; if (isServer) then { _trigger = _this select 0; _unit = _this select 1; if (!rps_param_ieds) exitWith {_trigger setpos [200,200];}; //disable IEDs by param, ignore the rest of this isServer loop! _speed = sqrt ( (velocity _unit select 0)^2 + (velocity _unit select 1)^2 + (velocity _unit select 2)^2 ); // getspeed is in different units _allowedSpeed = 3.9; //(_unit getSpeed "Normal")0.1; // For an infantry unit, slow/norm/fast are 2.7/4/6.666 or thereabouts // Check speed if (_speed > _allowedSpeed) then { _ammotype = _this select 2; _chance = _this select 3; _variance = _this select 4; if (isNil "_ammotype") then {_ammotype="B_30mm_HE";}; if (isNil "_chance") then {_chance=0.20;}; if (isNil "_variance") then {_variance=1;}; _chance = (_chance * 100); _variancey = random _variance  (_variance/2); _variance = random _variance  (_variance/2); _rand = random 100; if (_rand < _chance) then { _ammotype createVehicle [(getPos _unit select 0) + _variance,(getPos _unit select 1) + _variancey]; // place bomb within radius _trigger setpos [200,200]; // exploded, so no longer need trigger } else { if ( _rand > (98 min (100(_chance/10))) ) then { // each time it is run over but not exploded, there is a chance of accidentally defusing the bomb, min 2% but relative to the chance of the bomb actually going off _trigger setpos [200,200]; //complete dud; with _chance of 0.15 there is a 15% chance of detonation and a 2% (minimum) chance of defusal. 0.25 = 25%, 2.5% }; }; }; };
Mumble :: Thread :: Click to Join