Advertisement

Author Topic: Find Target that Player is pointing at  (Read 1188 times)

0 Members and 1 Guest are viewing this topic.

Offline Gnat

  • Addons Depot
  • Administrator
  • *****
  • I Bite!
    • Gnats
Find Target that Player is pointing at
« on: 03 Apr 2009, 18:49:04 »
Further to this thread
http://www.ofpec.com/forum/index.php?topic=32983.0
and its demo's code, I've taken much of it (thanks guys!) and used it to find the Target(s) the Player is pointing at or locked onto.
assignedTarget works fine for AI, but not for players.

The below code gets me very close, except because it uses a trigger box centered on the player/vehicle, the trigger not only overlaps the target in front, it also overlaps any target that may be 180 deg. behind the player. The trigger needs to only be forward of the player.

*** Need a little trigonometry help to center the trigger box out half way to the max range of detection, in line with the weapon facing (then rotate the trigger box).

BTW, the principle of this, place a long thin trigger box stretching out from the player in the direction of the weapon, wait 1 sec, then collect details of all targets within that long thin detector.

In my case, I will add code to select the closest of any targets found, and then send a Torpedo at it !
In general, because the trigger box is thin, it should mostly only find the 1 target.

Feed from "FIRED" EH
Quote
private["_ships", "_trigger", "_array", "_msg", "_dist", "_target", "_unit", "_weapon", "_range"];
_array = _this select 0;
_unit = _array select 0;
_weapon = _array select 1;

_range = 3000;
_trigger = createTrigger ["EmptyDetector", getPos _unit];
_trigger setTriggerActivation ["ANY", "PRESENT", false];
_trigger setTriggerArea [50, (_range/2), (((_unit weaponDirection _weapon) select 0) atan2 ((_unit weaponDirection _weapon) select 1)), true];
_trigger setTriggerType "NONE";
_trigger setTriggerStatements ["this", "", ""];
_trigger setTriggerTimeout [0, 0, 0, false];

_ships = [];
Sleep 1.0;
     
{
   if (_x isKindOf "Ship") then
   {
      if ((isEngineOn _x) && (side _x == West)) then
      {
         _ships = _ships + [_x];
      };
   };
} forEach list _trigger;

if (count _ships > 0) then
{        
   _msg = "";
   {
      _target = _x;
      _dist = _target distance _unit;
      _msg = _msg + format["Target:%1 - Range: %2\n", _target, _dist];
   } forEach _ships;
   hint format ["%1",_msg];
};
deletevehicle _trigger;
« Last Edit: 03 Apr 2009, 18:53:32 by Gnat »

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Find Target that Player is pointing at
« Reply #1 on: 03 Apr 2009, 19:34:36 »
Take a look at the first picture on this site:

x_offset = cos(a) * _range/2
y_offset = sin(a) * _range/2
« Last Edit: 03 Apr 2009, 19:38:19 by Worldeater »
try { return true; } finally { return false; }

Offline DeanosBeano

  • Addons Depot Staff
  • *****
  • SirDeanosbeano bstowed on me by sui ;)
    • Fraghaus
Re: Find Target that Player is pointing at
« Reply #2 on: 04 Apr 2009, 00:01:33 »

 hey Gnat,
 smetime ago,i was trying to achieve something similar for a laser pointer.
 what i did was to drop an invisible shape out from the players gun  and detected the nearestobjects within _x distance at intervals. maybe yo could detect "ship".
 anyway i used Mando_draw as my base , hope he dont mind me posting here ;).

 just start as you like . mando_draw is false in init for this one but change obviously.

 this sends a dropped light ut to 400m and returns anything of house in its path and sets its dammage to 1, its my very first tes, i cant find the latest one as always :).

 start with a trigger to test then as you like(this was set for a man with gun so mdel to world co-ords are far that.
  mando_draw = true ; res = [player] execvm "mando_draw.sqf"

 
 
Code: [Select]
// mando_draw.sqf by Mandoble

_range = 0;
_vol = 1.0;
_wei = 1.27;
_rdef = 5;

while {true} do
{
    if (_range > 400 ) then {
 _range = 0 };

   waitUntil {mando_draw};
   _range = _range + _rdef;
   _dir = player weaponDirection (weapons player select 1);
   _pos = player modelToWorld [0,0,.8];
   _posd = [(_pos select 0)+(_dir select 0)*_range,(_pos select 1)+(_dir select 1)*_range,(_pos select 2)+(_dir select 2)*_range];
   drop ["\ca\data\koulesvetlo","","Billboard",.1,2.8,_posd,[0,0,0],0,_wei,_vol,0.00,[1,1,1,1],[[1,1,1,1],[1,1,1,1],[1,1,1,1], [1,1,1,0]],[0],0,0,"whatsnear.sqf","",""];


   Sleep(0.01);
};


 whatsnear.sqf

 
Code: [Select]
_targ = nearestobjects [_this,["house"],15];

player sideChat format ["%1", _targ];

{
    _x setDammage 1;
}
forEach _targ;

 i know it needs mandos tag taking off and some Private statements at top, but i think with some tweaking it will be just the job for ya.
 p.s this is not mandos idea  or was not his intentins fr the script, but he knows i always twist them.
 ty mando and where are ya these days ?

 

I love ofp

Offline Gnat

  • Addons Depot
  • Administrator
  • *****
  • I Bite!
    • Gnats
Re: Find Target that Player is pointing at
« Reply #3 on: 04 Apr 2009, 01:31:40 »
Take a look at the first picture on this site:
x_offset = cos(a) * _range/2
y_offset = sin(a) * _range/2

Nice Link WE ! Thanks.
Think that codes a winner.


@DeanosBeano
Thanks mate, nice idea but I'm trying to avoid a) droping any sort of detectors onto the map b) using any the nearestobject commands as I think it can be a little laggy.

This code has to be intergral to an Addon, not a mission.
In my case it OK to wait 1 second for a hardcoded trigger to detect the items, as its only a Torpedo that has to wait to be launched after the trigger is pulled.

Cheers guys

OH, BTW, I think BIS need their arse kick for not suppling a simple command to return what the object that is within the Lock-Diamond ..... how hard would that have been really !?? ffs
« Last Edit: 04 Apr 2009, 01:34:43 by Gnat »

Offline savedbygrace

  • Mission Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: Find Target that Player is pointing at
« Reply #4 on: 04 Apr 2009, 06:20:39 »
I think BIS could use a slap in the face for many simple things that they failed to include, primarily AI functionality.  :dunno:

Offline kju

  • Members
  • *
    • PvPScene - The ArmA II multiplayer community
Re: Find Target that Player is pointing at
« Reply #5 on: 04 Apr 2009, 07:35:56 »
Sorry to hijack. :)

Could the target code also used to make a sound once an AA launcher locks onto a target?
Like if you have the target in the center of the cursor and have it there for a few seconds?

Disregard for the question how the current AA locking works.

Offline Gnat

  • Addons Depot
  • Administrator
  • *****
  • I Bite!
    • Gnats
Re: Find Target that Player is pointing at
« Reply #6 on: 04 Apr 2009, 11:07:31 »
Could the target code also used to make a sound once an AA launcher locks onto a target?
Like if you have the target in the center of the cursor and have it there for a few seconds?

No reason why not. Instead of using the FIRED EH, you simply run the detection on a continious loop.
When a target type of your choosing is found within the trigger box, a lock-on sound can be played, until its no longer in the trigger zone or maybe you "fired". The trigger zone will forever follow the facing of the weapon in question.
The problem is if theres more than 1 target within the trigger zone, theres only very complicated ways to determine which of those target the player is locked onto.
You could of course make the trigger zone VERY thin (3m ? ), so it could in theory be possible to only lock onto 1 target.

Mandoble,
With your HUD interfaces,  is it possible to visually highlight/throw a selector around an known object?

That could be 1 way to give the player indication of which of the targets it thinks you are pointing at.

Or, you simply just always select the closest.  :whistle:

EDIT
Sample Code for continuious scanning;
Quote
private["_ships", "_trigger", "_array", "_msg", "_dist", "_wdir", "_target", "_unit", "_weapon", "_drange"];
_unit = _this select 0;
_weapon = _this select 1;

_drange = 4000;
_wdir = ((_unit weaponDirection _weapon) select 0) atan2 ((_unit weaponDirection _weapon) select 1);
_trigger = createTrigger ["EmptyDetector", [(getpos _unit select 0) + (sin(_wdir) * (_drange/2)),(getpos _unit select 1) + (cos(_wdir) * (_drange/2)),0]];
_trigger setTriggerActivation ["ANY", "PRESENT", false];
_trigger setTriggerArea [15, (_drange/2), _wdir, true];
_trigger setTriggerType "NONE";
_trigger setTriggerStatements ["this", "", ""];
_trigger setTriggerTimeout [0, 0, 0, false];

Sleep 1.0;
while {true} do
{
_wdir = ((_unit weaponDirection _weapon) select 0) atan2 ((_unit weaponDirection _weapon) select 1);
_trigger setDir _wdir;
_trigger setpos [(getpos _unit select 0) + (sin(_wdir) * (_drange/2)),(getpos _unit select 1) + (cos(_wdir) * (_drange/2)),0];
_ships = [];
{
   if (_x isKindOf "Ship") then
   {
      if (side _x != (side _unit)) then
      {
         _ships = _ships + [_x];
      };
   };
} forEach list _trigger;

if (count _ships > 0) then
{        
   _msg = "";
   {
      _target = _x;
      _dist = _target distance _unit;
      _msg = _msg + format["Target:%1 - Range: %2\n", _target, _dist];
   } forEach _ships;
   hint format ["%1",_msg];
} else
{
   hint format ["NONE"];
};
sleep 0.01;
};
« Last Edit: 04 Apr 2009, 16:45:49 by Gnat »

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Find Target that Player is pointing at
« Reply #7 on: 06 Apr 2009, 11:19:21 »
Problem with BIS lock on is that you may use TAB to select a target which is not the one you have centered in your sight.

Offline Gnat

  • Addons Depot
  • Administrator
  • *****
  • I Bite!
    • Gnats
Re: Find Target that Player is pointing at
« Reply #8 on: 06 Apr 2009, 12:21:52 »
I know, but if this script does tell you what object to look for, will you HUD system be able to put its own lock box around it ?

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Find Target that Player is pointing at
« Reply #9 on: 06 Apr 2009, 15:31:29 »
I wonder why you are wandering around in "workaround land" (as vektorboson once called it). Isn't it possible to use the godBIS-given solutions? Like in: missile is to chopper what torpedo is to submarine...
« Last Edit: 06 Apr 2009, 18:21:45 by Worldeater »
try { return true; } finally { return false; }

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Find Target that Player is pointing at
« Reply #10 on: 06 Apr 2009, 16:25:03 »
I know, but if this script does tell you what object to look for, will you HUD system be able to put its own lock box around it ?

??
My HUD system already does that, check Vulcan as SAM for example (aiming with the Vulcan gun).