Forum Jump :

Author Message


Posts: 11
Rank:


Level: Member

Country: il
Location:
Occupation:
Age:
In-game name:

 
#1 Posted at 2016-07-17 19:32        
     
Hello all,

I want to create a script that draws the path of a unit in 3d.
I saw the bullet trajectory script, using drawline3d, but I was unsuccessful converting it to draw a trace behind a chosen unit.
Any ideas / existing script that you know of that can help?

Thanks in advance!


Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 57
In-game name: Kobayashi Maru

 
#2 Posted at 2016-07-17 23:54        
     
You can use this kind of script. Just replace cursorObject by what unit you want:

0 = [] spawn { ["trial", "onEachFrame", { 
  if (!isnull cursorObject) then { 
   drawLine3D [ASLToATL eyePos player, cursorObject, [1,0,0,1]]} 
}] call BIS_fnc_addStackedEventHandler}

Have a fun also with:
0 = [] spawn {  
  ["trial", "onEachFrame", {{   
    _aiming_vect = _x weaponDirection (currentWeapon _x);  
    _aiming_target = [(ASLToATL eyepos _x select 0) + 300* (_aiming_vect select 0),(ASLToATL eyepos _x select 1) +  300* (_aiming_vect select 1),(ASLToATL eyepos _x select 2) +  300* (_aiming_vect select 2)];  
    drawLine3D [ASLToATL eyePos _x, _aiming_target, [1,0,0,1]];  
  } forEach units group player}] call BIS_fnc_addStackedEventHandler
}

This post was edited by Pierre MGI (2016-07-18 00:09, 460 days ago)

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS

Advertisement


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 20
In-game name: Wak

 
#3 Posted at 2016-07-18 04:48        
     
Wrote a function for it, Wak_fnc_trackUnit:
/*
 * Author: 654wak654
 * "Tracks" a unit's movements by drawing lines following it's path
 *
 * Arguments:
 * 0: The unit to track <OBJECT>
 * 1: The distance between each line, lower the number the more accurate <NUMBER>
 * 2: Max amount of lines to draw for this unit <NUMBER>
 *
 * Return Value:
 * None
 *
 * Example:
 * [player, 20, 10] call Wak_fnc_trackUnit
 */

params [["_unit", objNull, [objNull]], ["_increment", 50, [0]], ["_max", 20, [0]]];

if (isNull _unit || {_increment < 2} || {_max < 2}) exitWith {};

if ((_unit getVariable ["sideColor", []]) isEqualTo []) then {
    _unit setVariable ["sideColor",
        [
            [0.7, 0.6, 0, 1], // Unknown
            [0, 0, 0.5, 1], // West
            [0.5, 0, 0, 1], // East
            [0, 0.5, 0, 1], // Indep
            [0.4, 0, 0.5, 1] // Civ
        ] select (([west, east, resistance, civilian] find side _unit) + 1)
    ];
};

[(_unit call BIS_fnc_netId) + "_trackerEH", "onEachFrame", {
    params ["_unit", "_increment", "_max"];
    if (driver vehicle _unit != _unit) exitWith {};

    _unitPos = (getPosVisual _unit) vectorAdd [0, 0, _unit selectionPosition "pelvis" select 2];
    _allLines = _unit getVariable ["allLines", [_unitPos]];
    _lastPos = _allLines select (count _allLines - 1);
    if (_unit distance _lastPos > _increment) then {
        _allLines pushBack (_unitPos);
        if (count _allLines > _max) then {
            _allLines deleteAt 0;
        };
    };
    _unit setVariable ["allLines", _allLines];

    drawLine3D [_lastPos, _unitPos, _unit getVariable "sideColor"];

    if (count _allLines < 2) exitWith {};

    _lastX = _allLines select 0;
    {
        drawLine3D [_lastX, _x, _unit getVariable "sideColor"];
        _lastX = _x;
    } forEach (_allLines select [1, count _allLines]);
}, [_unit, _increment, _max]] call BIS_fnc_addStackedEventHandler;

To stop tracking a unit you'll need this code:
[
    (_unit call BIS_fnc_netId) + "_trackerEH",
    "onEachFrame"
] call BIS_fnc_removeStackedEventHandler;



This post was edited by 654wak654 (2016-07-18 04:55, 460 days ago)

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Author Message


Posts: 1589
Rank:


Level: Member

Country: pf
Location: Tahiti
Occupation: too many Arma
Age: 57
In-game name: Kobayashi Maru

 
#4 Posted at 2016-07-18 06:25        
     
Nice work Wak! Could you place it in script library plz?

PLEASE CONTACT ME ON BI FORUMS FOR ANY SCRIPT / MOD QUESTION. TKS





Tags: Draw, Path