Home   Help Search Login Register  

Author Topic: Detect if the player is lasing a target and referencing laser target  (Read 1529 times)

0 Members and 1 Guest are viewing this topic.

Offline Dash5

  • Members
  • *
I'm working on a simple airstrike script that makes a GBU-12 fly out of the sky and hit a target.

I'd like to:

1. detect if the player is using the laser designator
2. reference the laser dot created by the laser designator

When I was searching the forum for an answer, I saw some references to Snypir's LD guide in the Editor's Depot, but I can't find it there.


Offline Dash5

  • Members
  • *
Thanks, That answers #2.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
For question 1, you may try a "fired" event hander, which also would try to detect the laser dot coordinates. But even it this case, always exists the posibility of having two units using the designator at the same time over the same area. To solve that case is a "bit" more difficult, you need the weaponDirection command.

This command returns the direction vector of the unit's weapon (note that this is a vector, not a direction in degrees). Lets say you get that vector in the "fired" event script. Now you detect the presence of laser designators (as resolved in question 1) and you get also its deviation in relation to player, that is, the direction where the player should head to align with that "object". The angle difference between the laser object of the player and the weapon direction of the player should be minimum, in fact, quite close to 0, this way you may be sure that a laser object out of many ones present, is the laser dot of the player.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Is there any reason why you could not calculate the angular difference between the direction the player is facing and the direction from the player to the laser target? Would be simpler.

ismytarget.sqf
Code: [Select]
private ["_unit", "_target", "_tol", "_xu", "_yu", "_diru", "_xt", "_yt", "_dirt"];
_unit = _this select 0;
_target = _this select 1;
_tol = _this select 2;

_xu = (getPos _unit) select 0;
_yu = (getPos _unit) select 1;
_diru = getDir _unit;
_xt = (getPos _target) select 0;
_yt = (getPos _target) select 1;

_dirt = (90 - (_yt - _yu) atan2  (_xt - _xu)) mod 360;
if (abs (_dirt - _diru) <= abs _tol)
{TRUE}
else
{FALSE}

Hopefully I haven't dropped a parenthesis....

Then:
Code: [Select]
_ismytarget = [_unit, _target, 5] call compile "ismytarget.sqf"should give TRUE if the angle difference is less than 5 degrees and FALSE otherwise.

You could also precompile the code in your init.sqf:
Code: [Select]
isMyTarget = compile "ismytarget.sqf"so that:
Code: [Select]
_ismytarget = [_unit, _target, 5] call isMyTarget
 :no:Warning: above code has not been tested and may cause anal leakage! :no:
« Last Edit: 17 May 2007, 16:15:33 by Mr.Peanut »
urp!