Bug #16947

function canSee flawed

Added by Fireball almost 5 years ago. Updated almost 5 years ago.

Status:Closed Start date:01/24/2011
Priority:Normal Due date:
Assignee:Fireball % Done:


Target version:0.74
Affected Version:0.72 GPU VRAM size:
Operating system: I am using some Mods:
Graphics card: Reproducible for you:
Difficulty: Related to content of DLC:
CPU: Affected ArmA3 version:
System RAM size: Single / Multi Player?:


Function canSee does not work correctly with certain bearings of the player.

When getDirTo is:

#define getDirTo(X,Y)       (((if(typeName Y == "OBJECT")then{getPosATL Y}else{Y} select 0) - (getPosATL X select 0)) atan2 ((if(typeName Y == "OBJECT")then{getPosATL Y}else{Y} select 1) - (getPosATL X select 1))) 

And canSee is:

// canSee; returns true if a _unit looks at the _obj within a certain _arc (field of view) in degrees
canSee = {
    private ["_unit","_obj","_dirTo","_uDir","_vcl","_arc"];
    _unit  = _this select 0;
    _obj   = _this select 1;
    _arc   = _this select 2;

    _dirTo = abs(getDirTo(_unit,_obj)); // vector from _unit to _obj
    _uDir  = getDir (vehicle _unit); // heading of _unit
    if (vehicle _unit != _unit) then {
        // if it's a vehicle and _unit is in a turret we take the heading of that turret
        _vcl = vehicle _unit;
        if (_vcl turretUnit [0] == _unit) then {
            _uDir = _vcl weaponDirection (_vcl weaponsTurret [0] select 0);
            _uDir = (_uDir select 0) atan2 (_uDir select 1);
    if (abs(_dirTo - _uDir) > 180) then { _dirTo = -1*(360 - _dirTo); };
    abs(_dirTo - _uDir) <= _arc

#define canSee(X,Y,Z) ([X,Y,Z] call canSee)


Updated by Fireball almost 5 years ago

  • Status changed from Assigned to Resolved
  • Target version set to 0.74
  • % Done changed from 30 to 100

Testing with gaia's console and two units led to the insight that not _dirTo needs correction but _uDir, since _uDir will be > 180 depending on the heading of _unit. Fix applied.

Updated by Fireball almost 5 years ago

  • Category set to Misc

Updated by Fireball almost 5 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF