Wolfenswan
04-01-2012, 04:19 PM
Though arma knows speed (http://community.bistudio.com/wiki/speed) to return a unit's movement speed, this unfortunately only returns km/h, making it incomparable to getSpeed (http://community.bistudio.com/wiki/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 (http://community.bistudio.com/wiki/velocity).:
In the example, a unit sets off a trigger that activates nul=[thisList] execVM "speedcheck.sqf"
_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];};
Placing this trigger in a mission using the F2 framework you can use debug mode to finetune the allowedspeed to your leisure. E.g. _allowedSpeed = ((_unit getSpeed "Normal")-0.5)) reduces the allowed speed to everything slower than a crouched jog.
Thanks to Nullkigan for coming up with the codestuff.
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 (http://community.bistudio.com/wiki/velocity).:
In the example, a unit sets off a trigger that activates nul=[thisList] execVM "speedcheck.sqf"
_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];};
Placing this trigger in a mission using the F2 framework you can use debug mode to finetune the allowedspeed to your leisure. E.g. _allowedSpeed = ((_unit getSpeed "Normal")-0.5)) reduces the allowed speed to everything slower than a crouched jog.
Thanks to Nullkigan for coming up with the codestuff.