Jump to content
Sign in to follow this  
Tankbuster

Is player pointing weapon at object?

Recommended Posts

Guys,

I want to be able to know, in script, when a player is looking at a particular object. Specifically, when they are holding my upcoming IED detector device (a reconfigged and remodeled pistol) and when they are pointing at one of my hidden IEDs. It will beep at them, the closer they are when pointed at the IED, the faster the beeps.

I've scoured the biki and the comref and done a few early test, with disappointing results.

weaponDirection returns a vector, which I don't understand. I don't understand what data it's presenting to me, nor how it could be used. I don't understand what a vector is. I wonder if screenToWorld has anything to do with this?

aimPos seemed to have promise. The biki says it's the objects aiming position, but for a player holding a pistol, it simply returns the players pos. I was hoping it might return the pos of the aimed target.

aimedAtTarget didn't apparently do anything. It returned zero even when I aimed directly at the given target.

cursorTarget is the only thing that's given me any joy so far. It returns the object that I'm looking at. If I combine that with a check to see if the player has detector as main weapon in hand and is less than 10m from cursor target when cursor target = myIED then I can make an alarm noise for the player. At least, that's the theory. I worry about the biki references to knowsAbout from cursorTarget. The whole idea of my IED system is that they are completely or partially hidden from view by clutter objects and so the player may not knowabout the IED.

Are there any other commands or functions that might be of use to me?

If weaponDirection is the way forward for me, can it be explained to me in quite small words? :)

Any other comments and help gratefully received.

Share this post


Link to post
Share on other sites

From wht I can gather about weaponDirection it's returning a simple array with xzy (notice the z in the middle, not the end) coordinates, but I'm not entirely sure if you could perform a check with it, something like this maybe?:

_weapdir = player weapondirection "fancyieddevice";
if ((_weapdir select 0) distance MyIED < 100 || (_weapdir select 2) distance MyIED < 100) then {
//code and such
};

cursorTarget requires the IED to have been spotted atleast once (it's like the info age in the editor (although that never works)) by friendly troops for it to work apparently.

(Edit)

Not even sure if distance is useable here since that isn't a position. The idea is to check for the distance though.

Share this post


Link to post
Share on other sites

[/color]

From wht I can gather about weaponDirection it's returning a simple array with xzy (notice the z in the middle, not the end) coordinates, but I'm not entirely sure if you could perform a check with it, something like this maybe?:

_weapdir = player weapondirection "fancyieddevice";
if ((_weapdir select 0) distance MyIED < 100 || (_weapdir select 2) distance MyIED < 100) then {
//code and such
};

Yeah, I saw the output from weapondirection was [x,z,y]. It returns numbers between -1 and 1, not coordinates its a 3d vector.

I currently wading though the BIS function viewer to see if there's anything of interest in there.

Share this post


Link to post
Share on other sites

Hi,

You can use cursorTarget:

if (!isNull cursorTarget) then {
  if (cursorTarget == someobject) then {
     //Looking at someobject
  };
};

On the weaponDirection wiki page also shows how you can convert it to degrees:

_array = _this weaponDirection "weapon class" ;
_dir_degrees = (_array select 0) atan2 (_array select 1);

Edited by neokika

Share this post


Link to post
Share on other sites

I used Cursortarget for known target combined with screentomodel so when there is no real target it will target an area for for fake artillery strikes.

Point at the target or position and use a radio trigger to call the strike.

radio trigger

repeating

on act

null=[5,400,25,80] execvm "bombs.sqf"

//null=[5,400,25,80] execvm "bombs.sqf"

if (!isServer) exitWith {};

 private "_ammo";

_ammotype = _this select 0; // type of ammo
_height   = _this select 1; // height of drop
_rounds   = _this select 2; // how many
_spread   = _this select 3; // area

_pos  = screenToWorld [0.5,0.5];// land position 
if (!isnull cursortarget) then { _pos = getpos cursortarget};// building / object position

switch (_ammotype) do {
case 0:{_ammo = "R_57mm_HE"};
     case 1:{_ammo = "Sh_105_HE"};
     case 2:{_ammo = "Bo_GBU12_LGB"};
     case 3:{_ammo = "M_Stinger_AA"};
     case 4:{_ammo = "R_80mm_HE"};
     case 5:{_ammo = "ARTY_Sh_122_HE"};
     case 6:{_ammo = "Sh_85_AP"};
     case 7:{_ammo = "Bo_FAB_250"};
     case 8:{_ammo = "Grenade"};
           };

for "_x" from 1 to _rounds do {
 sleep random 0.8;
  _bomb = _ammo createVehicle [( _pos select 0)+(random _spread)-_spread/2, (_pos select 1)+(random _spread)-_spread/2,_height];
_bomb setVectorUp [0, 9, 0.1];
};

_pos will contain the position of target.

It may not be very accurate though.

Share this post


Link to post
Share on other sites

According to biki, cursorTarget only works if the player knowsAbout the object. That's a problem for me because the whole idea is that the IEDs they are looking for are hidden under clutter objects. That said, I could always tie up the IED and the clutter object hiding it and go at it that way.

That said, I've not tested cursorTarget exhaustively. I'm going to do that now.

---------- Post added at 21:24 ---------- Previous post was at 21:18 ----------

_pos will contain the position of target.

It may not be very accurate though.

I need it to be fairly accurate. I'm talking within half a meter at 15 meters distance. I don't think your method will achieve that but I will test.

Another thing has occurred to me, though.

The player and his pistol/handheld detector will usually be at ground level. The IEDS are always at ground level. So, relative to the player, up and down are not really relevant. Only left and right, and of course distance is relevant. My theory falls apart a bit if a player is up on a roof top waving his detector around, but other than that, as far as I can see, only bearing and distance are really relevant here.

Share this post


Link to post
Share on other sites

Tankbuster, would eyeDirection([93622] New: Scripting function eyeDirection.) work for you. If so, check out SaOk's thread on LOS:

Line Of Sight (Example Thread)

I see also these:

[93598] New: Scripting functions eyePos object and aimPos object

Maybe even something like Mando Angles

Edited by panther42

Share this post


Link to post
Share on other sites

Surprisingly I just tested it and I can locate objects reasonably well, the difficulty is getting useful pings.

Also if the weapon points at the sky it seems to turn off for a while.

I assume it's a distance thing.

You also need an object to test place one and name it test

For testing I create a suitcase to act as a real world pointer.

//sleep (_dist / 100); remove the // to hear directional pings

_thing = "suitcase" createvehicle [0,0,0];

While {true} do 
{


_pos  = screenToWorld [0.5,0.5];// land position 
//if (!isnull cursortarget) then { _pos = getpos cursortarget};// building / object position

_dist = [_pos select 0,_pos select 1,_pos select 2] distance test;
_thing setpos _pos;
//sleep (_dist / 100);  
sleep 0.1;	
hint str _pos ;
};

Obviously it's basic and just a proof of concept.

There is also the actual tracker function that would give a visual location.

Edited by F2k Sel

Share this post


Link to post
Share on other sites
Tankbuster, would eyeDirection([93622] New: Scripting function eyeDirection.) work for you. If so, check out SaOk's thread on LOS:

Line Of Sight (Example Thread)

Possibly, though I'm looking for weapon point rather than eyeline. TrackIR users (I'm one) would get very odd results.

---------- Post added at 23:39 ---------- Previous post was at 23:36 ----------

[93598] New: Scripting functions eyePos object and aimPos object

Maybe even something like Mando Angles

aimPos doesn't work as expected. It simply returns the pos of the player, not of his target.

Mando Angles is quite old and has been superceded by bis functions.

---------- Post added at 23:40 ---------- Previous post was at 23:39 ----------

Im going to plug the cursorTarget into my (released just today) latest version of the demo mission that this is going to be used in and see how it works with objects the player doesn't knowabout.

Share this post


Link to post
Share on other sites

I would have thought aimedAtTarget would be ideal for this? I've used it very successfully - the weapon string is optional did you try it without that 1st? eg:

_aimingQuality = heli AimedAtTarget [target];

with the above it should return with any weapon you point at the given target.

Example of successful use here - the A10 kills everthing it points at:

http://forums.bistudio.com/showthread.php?143761-A10-gun-run-script&p=2267304&viewfull=1#post2267304

Relevant code from that script:

while {alive _unit} do {
_Atarget = assignedTarget _unit;
  _epos = getPosATL _Atarget;
    _aimingQuality = _unit AimedAtTarget [_Atarget];

if (_aimingQuality >= 0.7) then {
 _pilot sidechat "Hog22: Attacking hostile vehicles - guns!";
   var_gunRuns = var_gunRuns +1;

_Atarget say3D "A10rounds";
 _unit say3D "A10attack2";

[_epos] call fnc_steelrain;
 sleep 6;
   };

If you modify that loop with "if (_aimingQuality >= 0.7) then {" increments from 0.1 - 1 - beeping louder and faster each time, it should do it? Getting it to do it for a specific weapon might be tricky with the className but it should work.

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

I still think screenToWorld [0.5,0.5] is the way to go, If you link a nearestobject command to it it can find objects of that type even when you can't see them.

Share this post


Link to post
Share on other sites
I would have thought aimedAtTarget would be ideal for this? I've used it very successfully - the weapon string is optional did you try it without that 1st? eg:

_aimingQuality = heli AimedAtTarget [target];

with the above it should return with any weapon you point at the given target.

Example of successful use here - the A10 kills everthing it points at:

http://forums.bistudio.com/showthread.php?143761-A10-gun-run-script&p=2267304&viewfull=1#post2267304

hint format ["%1", dude aimedAtTarget [bucket, "BAF_L85A2_RIS_ACOG" ]];

I haven't tried it without weapon,but this returned zero what ever I aimed it at.

---------- Post added at 02:16 ---------- Previous post was at 02:13 ----------

I still think screenToWorld [0.5,0.5] is the way to go, If you link a nearestobject command to it it can find objects of that type even when you can't see them.

I know what you mean, but the problem with screenToWorld is that it doesn't take into account floating zone, headmovement or TrackIR users.

Share this post


Link to post
Share on other sites

I've never used TrackIR, but head movement does stop it from functioning.

I think aimedAtTarget is only for AI and may be only for vehicles.

Share this post


Link to post
Share on other sites
I think aimedAtTarget is only for AI and may be only for vehicles.

I'm beginning to think so too. More tests tomorrow.

Share this post


Link to post
Share on other sites

Yep aimedAtTarget is only for vehicle turrets/aircraft and doesn't seem to work on small objects or "man" targets. I got it to return on the toilet (yipee! :yay:), vehicle ammo box, H barrier cube, all vehicles, statics, military objects but not things like IEDS, signs, rucksacks, mines or buckets.

Also it doesn't increse or decrease in a linear fashion - seems to jump from 0 - 0.9ish once you get the crosshairs roughly central.

while {true} do {
_Atarget = cursorTarget;
_aimingQuality = player AimedAtTarget [_Atarget];
hintSilent format["CT:%1|Aim:%2",_Atarget, _aimingQuality];
sleep 0.1;
};

conclusion: It aint what you want :(

Share this post


Link to post
Share on other sites

OK, done some very boring tests that gave some interesting results

My IED kit test mission spawns a bunch of street clutter objects and under some of them is an IEDs.

cursorTarget can see the clutter objects just fine and the knowsAbout (KA) value of them is usually 4. The KA value of the IEDs is often 4, usually a bit less but almost always more than 3.

But cursorTarget never sees them unless there's large parts of the IED model exposed. And with some clutter objects, the landpillow for example, even if the IED is partially in view, cursorTarget cannot pick it up.

revealing (the command) has some effect on the KA value of the IEDs but never increases the ability of cursorTarget of the IEDs. Arse.

I need cursorTarget to be able to pick up unseen IEDs and was hoping increasing the KA using nearTargets and reveal, would allow cursorTarget to see them even when hidden, but it doesn't. As I say... arse.

---------- Post added at 17:48 ---------- Previous post was at 17:36 ----------

I-ToVVkrw7s

There's an IED under the TV. I know there is because there's a red helper object there and debug says the TV and IED are in the same pos.

When I first look at it, you can see the cursorTarget and KA of the TV. All good.

At this point the KA of the IED is 3.1. Halfway through and unseen by the vid, the KA of the IED is increased in script to 4 and this is verified later by debug.

But cursorTarget still doesn't see the IED.

Share this post


Link to post
Share on other sites

What about the new aimPos and eyePos commands?

Compare aimPos with getPosASL _myIED and beep if the [x,y,z] coords are withing a certain range of each other?

Untested:

_man = _this select 0;
_ied = _this select 1;
while {true} do{
_a = aimPos _man;
_b = getPosASL _ied;
if (_a distance _b <= 10) then {hint "there's an ied where ur aiming!"};
sleep 0.1;
};

http://community.bistudio.com/wiki/aimPos

http://community.bistudio.com/wiki/eyePos - you could have IED detecting bionic eyes with this? lol

edit: tested!

No don't bother with those either - someone at BIS is having a joke with those? Seem to do the same thing as getPosASL player? You can walk / drive backwards to the ied and it sets off the hint WTF?

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites
What about the new aimPos and eyePos commands?

Compare aimPos with getPosASL _myIED and beep if the [x,y,z] coords are withing a certain range of each other?

Untested:

_man = _this select 0;
_ied = _this select 1;
while {true} do{
_a = aimPos _man;
_b = getPosASL _ied;
if (_a distance _b <= 10) then {hint "there's an ied where ur aiming!"};
sleep 0.1;
};

http://community.bistudio.com/wiki/aimPos

http://community.bistudio.com/wiki/eyePos - you could have IED detecting bionic eyes with this? lol

edit: tested!

No don't bother with those either - someone at BIS is having a joke with those? Seem to do the same thing as getPosASL player? You can walk / drive backwards to the ied and it sets off the hint WTF?

I coun't get you code to return anything useful according to the wiki it only "Returns the object's (main turret) aiming position." (not the actual targrt position)

A working script that someone posted is as follows all though I find it works better when the player is b and target a.

//Player
_a = _this select 0;
//AI to see or not
_b = _this select 1;
while {true} do {
_eyeDV = eyeDirection _b;
_eyeD = ((_eyeDV select 0) atan2 (_eyeDV select 1));
if (_eyeD < 0) then {_eyeD = 360 + _eyeD};
_dirTo = [_b, _a] call BIS_fnc_dirTo;
_eyePb = eyePos _b;
_eyePa = eyePos _a;
if ((abs(_dirTo - _eyeD) >= 90 && (abs(_dirTo - _eyeD) <= 270)) || (lineIntersects [_eyePb, _eyePa]) || (terrainIntersect [_eyePb, _eyePa])) then {hintsilent "NOT IN SIGHT";} else {hintsilent "IN SIGHT"};
sleep 0.1;
};

Them main problem is that it will still only work when detecting an AI or maybe player unit.

If you can only use cursortarget then a good object to use is an ATV it can be detected when placed just below the surface, it has a very large detection area above the vehicle.

There's also the "invisibleman_EP1" that can also be detected using cursortarget.

ACE has invisible targets that should work.

Edited by F2k Sel

Share this post


Link to post
Share on other sites
What about the new aimPos and eyePos commands?

Compare aimPos with getPosASL _myIED and beep if the [x,y,z] coords are withing a certain range of each other?

edit: tested!

No don't bother with those either - someone at BIS is having a joke with those? Seem to do the same thing as getPosASL player? You can walk / drive backwards to the ied and it sets off the hint WTF?

Yes, I already found this. aimPos returns the players position. I haven't tried it in a vehicle - not that that would help me - I suspect aimPos might be designed for turrets rather than hand held weapons. I've not tested eyePos, but am not surprised it's broken too.

---------- Post added at 21:47 ---------- Previous post was at 21:38 ----------

If you can only use cursortarget then a good object to use is an ATV it can be detected when placed just below the surface, it has a very large detection area above the vehicle.

There's also the "invisibleman_EP1" that can also be detected using cursortarget.

ACE has invisible targets that should work.

Yes, I thought about this. invisible man gives problems because he has a fire geometry, so bullets, rockets and explosions will hit him.

I do think cursorTarget is the way to go, it's just a matter of rigging a decent target for it. We already know it's not good at seeing obscured objects.

There are other invisible objects. There's a fence -actually, there's 3 invisible fences. I'm going to test them. There's other possibilities, such as a game logic or the heli-empty.

There's also the possibility of having cursorTarger react to when it sees the clutter object that is hiding the IED. This should be simple. If the cursor target is in clutterobject array and is within half a meter of an IED, make detector go beep.

---------- Post added at 21:50 ---------- Previous post was at 21:47 ----------

ACE has invisible targets that should work.

I'm not using ACE. In fact I absolutely can not use it. Something it's done breaks the BIS satchel that my disruptors are based on.

But that said, I'm using the tky_ied addon anyway, perhaps I should make an invisible target object myself. I suck at teh modelling. Well.. I say that, I might absolutely rock at it. Never tried. :)

Share this post


Link to post
Share on other sites

Actually I just tried invisible targets in another mod and cursortarget didn't detect them either, I guess it make sense that the player cant's see them.

Invisiblefence, clutter, gamelogic and heli pad aren't detected by cursortarget either I know that from past experience.

I'm wondering if any object that has no geometry can be detected by cursortarget.

Share this post


Link to post
Share on other sites

Ah OK, thanks for that. Saves me doing it. :) So, next effort is to tie the street clutter object in with the IED and have cursorTarget react to that.

Share this post


Link to post
Share on other sites

Meditated a bit while watching Predators and it occurred to me that if you know the positions of the playableUnits and IEDS you can:

-build 2 arrays of positions and compare 1 with the other - distance;

-for each playableUnit you can locate the closest IED and get the direction to it - degrees;

    _dx = (_iedPos select 0) - (_manPos select 0);
     _dy = (_iedPos select 1) - (_manPos select 1);
       _dirTo = _dx atan2 _dy;
if (_dirTo < 0) then {_dirTo = _dirTo + 360};

-you can get the direction of the playableUnit and compare that with the above dirTo.

All that gives you everything you need for the 2D - horizontal axis, to get everything you want, you of course need the vertical axis which takes you back to screenToWorld so can everything be done with this?:

-screenToWorld will give you a position on the players screen

-modelToScreen will give you the position of the IED on the players screen

-distance can check if you are close enough

-terrainIntersect and lineIntersects will check if the object is blocked by another object or the terrain.

You also might need the safezone commands as some people have more than 1 monitor / different sizes and the screen area is different:

http://community.bistudio.com/wiki/SafeZone

To edit a safezone they recommend the User Interface Editor:

http://community.bistudio.com/wiki/User_Interface_Editor_%28Arma_2%29

Edited by Mattar_Tharkari

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×