Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
Tajin

Ideas for a "aimedAtTarget" workaround

Recommended Posts

Here's the situation:

I'm trying to check if person A is aiming at person B.

- I can't use "cursorTarget" as I want to use it remotely and don't want to be restricted to players only.

- I can't use "aimedAtTarget" as that command currently only works for Vehicles.

- I've also tried using "lineIntersectsWith" in combination with "Aimpos" and "weaponDirection", however that command seems to be unable to detect intersections with people.

Those are all the possibilities I can currently think of, so I'm running out of options.

Does anyone have another idea for a possible workaround?

---------- Post added at 12:34 AM ---------- Previous post was at 12:11 AM ----------

Ok, while writing this post I had another idea which I'm currently testing.

It involves multiplying the weaponDirection with the distance to the other person and then checking the distance of the resulting position to the actual position of the other person.

Kind of a crude solution but it might just suffice for what I'm trying to do.

Still hoping for better suggestions though. :)

Share this post


Link to post
Share on other sites

- I've also tried using "lineIntersectsWith" in combination with "Aimpos" and "weaponDirection", however that command seems to be unable to detect intersections with people.

Neither sure if this is what you're looking for, nore if there's slicker ways to do this, but this adaptation of SaOk's LOS function works for me:


private ["_a","_b","_WDir","_WDeg","_abs","_bolean","_range"];

//Unit to be in line of weapon
_a = _this select 0;

//Ai with the weapon in question
_b = _this select 1;

_bolean = false;
if (weaponlowered _b) exitwith {_bolean};

_WDir = _b weaponDirection (currentweapon _b);
_WDeg = ((_WDir select 0) atan2 (_WDir select 1));
_dirTo = [_b, _a] call BIS_fnc_dirTo;
_Pb = eyepos _b;
_Pa = eyepos _a;
_abs = abs(_dirTo - _WDeg); 
_range = _abs >= 19 && _abs <= 338;

if (_range || (lineIntersects [_Pb, _Pa]) || (terrainIntersectASL [_Pb, _Pa])) then {
//hintsilent "NOT IN SIGHT";
_bolean = false; 
} else {
//hintsilent "IN SIGHT";
_bolean = true;
};

_bolean;

-> This is what I use to check if unit _a is within the "light cone" of unit _b's weapon flashlight. Play around with the _range definition to see what works for you.

One disclaimer though: If I remember correctly, the function can return as true even if the _b is pointing his weapon to the ground. For that reason, I also use an array to check if the unit's animationstate is one where the weapon is up: -> edit: fixed via weaponlowered command

Oh and another disclaimer: I couldn't figure out how to include a vertical value in _range, so it only checks left and right.

Edited by Mad_Cheese

Share this post


Link to post
Share on other sites

So here's the function that I'm using now:

private ["_actor","_target","_wpn","_pos0","_pos1","_wdir","_dst","_pos2","_deviation","_aiming"];

_actor = _this select 0;
_target = _this select 1;


if (weaponLowered _actor || isNull _actor || isNull _target) exitWith {};

_wpn = currentWeapon _actor;
_pos0 = getPosASL _actor;
_pos1 = getPosASL _target;
_wdir = _actor weaponDirection _wpn;
_dst = _pos0 distance _pos1;
_pos2 = [(_pos0 select 0) + _dst * (_wdir select 0), (_pos0 select 1) + _dst * (_wdir select 1), (_pos0 select 2) + _dst * (_wdir select 2)];
_deviation = _pos2 distance _pos1;

(_deviation < 0.7)

Returns true if _actor has his weapon pointed roughly at _target. It has a slight tolerance to the left and right, but it wont fire if you're aiming at the targets feet.

I'm using this for a civilian behaviour FSM. When a civilian notices an armed person getting too close to him, he will run away and hide somewhere. However, if the armed person is aiming at him, he will not dare to run and will instead raise his arms. So for my purpose it makes sense that the civilian doesn't feel threatened when a soldier is "aiming" at his feet. (only downside is that it doesn't work on prone persons)

---------- Post added at 01:47 AM ---------- Previous post was at 01:41 AM ----------

Thank you Mad_Cheese, that is an interesting script. Though it might be a bit more costly than what I'm using now.

I might add a visibility check (lineIntersects) to my variant too, totally forgot about that but I'm not sure if I actually need it.

btw. you can use http://community.bistudio.com/wiki/weaponLowered instead of checking animations. The cool thing about it is, that it also returns true when the unit has no weapon at all.

Edited by Tajin

Share this post


Link to post
Share on other sites

jeez! weaponlowered, I had no idea... My script is from A2 :) To hell with that array then.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×