Jump to content

Recommended Posts

Okay, so i'm trying to get drawIcon3D to work the same way as the code below, however this only shows the units drawicon3d if the player's eyes are in view of the unit.  I would like for it to be in the view of the players camera (internal or external) rather than the eye position of the player, thanks in advance to anyone willing to help me as it has been annoying me for a long time.

 

if (!(lineIntersects [eyePos vehicle cameraOn, eyePos _unit, vehicle cameraOn, _unit]) && isNull objectParent _unit) then {

drawIcon3D['', _colour, _pos, 0, 1.0, 0, _name, 1, 0.0345, "RobotoCondensed", "center", false];

};

 

Share this post


Link to post
Share on other sites
32 minutes ago, Larrow said:

Would you be able to re-structure the if statement for me so I understand how to use it in the way that I want it to work?

Share this post


Link to post
Share on other sites

Untested

if ( isNull objectParent _unit && { !(lineIntersects [positionCameraToWorld, eyePos _unit, cameraOn, _unit]) } ) then {
	drawIcon3D['', _colour, _pos, 0, 1.0, 0, _name, 1, 0.0345, "RobotoCondensed", "center", false];
};

 

Share this post


Link to post
Share on other sites

Yeah I used the if statement and it threw this error:

https://gyazo.com/7c8aceeb3f1ee8f30797c2e1ecfae0e2

 

Was using this for the test:

ShowNameTags = addMissionEventHandler ["Draw3D",{  
  _units = [];  
  {  
    if (side _x == civilian || side _x == west || side _x == independent) then {  
     _units pushBack _x;  
    };  
  } forEach allUnits;  
 
  {  
    _unit = _x; 
    _distance = cameraOn distance _unit;  
    _alpha = 1.5 - (_distance / 12);  
    _colour = [0,1,0,_alpha];  
    _crew = crew (vehicle _unit);  
    _veh = vehicle _unit;  
    _name = '';  
 
    { 
        _name = format ["%1", name _unit];  
  
   }forEach _crew;  
  
    _bounding = boundingBoxReal _veh;  
    _b1 = _bounding select 0;  
    _b2 = _bounding select 1;  
    _maxHeight = (abs ((_b2 select 2) - (_b1 select 2)));  
  
    _pos = visiblePosition _veh;  
    _height = (_b2 select 2) + ((getPosATL _veh) select 2);  
    _maxHeight = _maxHeight - 0.37;  
    _pos set[2,_height];  
    _pos = _unit modelToWorldVisual [((_unit selectionPosition "head") select 0)-0.05, ((_unit selectionPosition "head") select 1), ((_unit selectionPosition "head") select 2) + 0.7  + (_distance / 12) / 1.5];  
if ( isNull objectParent _unit && { !(lineIntersects [positionCameraToWorld, eyePos _unit, cameraOn, _unit]) } ) then { 
     drawIcon3D['', _colour, _pos, 0, 1.0, 0, _name, 1, 0.0345, "RobotoCondensed", "center", false];   
    };  
  }forEach _units; 
}];

 

Share this post


Link to post
Share on other sites

Sorry I forgot to add the camera offset to the command. Tested, just removed some of your unused variables.

ShowNameTags = addMissionEventHandler [ "Draw3D", {

	{
		_unit = _x;

		_distance = cameraOn distanceSqr _unit;
		_colour = [ 0, 1, 0, 1.5 - ( _distance / ( 12^2 )) ];

		_name = "";
		{
			_name = format [ "%1%2%3", _name, [ endl, "" ] select ( _name == "" ), name _unit ];
		}forEach crew vehicle _unit;

		_unit selectionPosition "head" params[ "_headX", "_headY", "_headZ" ];
		_pos = _unit modelToWorldVisual [ _headX - 0.05, _headY, _headZ + 0.7  + (_distance / ( 12 ^ 2 )) / 1.5 ];
		if ( isNull objectParent _unit && { !( lineIntersects [ positionCameraToWorld [ 0, 0, 0 ], eyePos _unit, cameraOn, _unit ]) } ) then {
			drawIcon3D[ '', _colour, _pos, 0, 1.0, 0, _name, 1, 0.0345, "RobotoCondensed", "center", false ];
		};
	}forEach ( allUnits select { side _x in [ civilian, west, independent ] } );
}];

 

Share this post


Link to post
Share on other sites
6 minutes ago, Larrow said:

Sorry I forgot to add the camera offset to the command. Tested, just removed some of your unused variables.


ShowNameTags = addMissionEventHandler [ "Draw3D", {

	{
		_unit = _x;

		_distance = cameraOn distanceSqr _unit;
		_colour = [ 0, 1, 0, 1.5 - ( _distance / ( 12^2 )) ];

		_name = "";
		{
			_name = format [ "%1%2%3", _name, [ endl, "" ] select ( _name == "" ), name _unit ];
		}forEach crew vehicle _unit;

		_unit selectionPosition "head" params[ "_headX", "_headY", "_headZ" ];
		_pos = _unit modelToWorldVisual [ _headX - 0.05, _headY, _headZ + 0.7  + (_distance / ( 12 ^ 2 )) / 1.5 ];
		if ( isNull objectParent _unit && { !( lineIntersects [ positionCameraToWorld [ 0, 0, 0 ], eyePos _unit, cameraOn, _unit ]) } ) then {
			drawIcon3D[ '', _colour, _pos, 0, 1.0, 0, _name, 1, 0.0345, "RobotoCondensed", "center", false ];
		};
	}forEach ( allUnits select { side _x in [ civilian, west, independent ] } );
}];

 

Thanks a lot for the help, however the line intersects doesn't actually work and i can see the tag through walls:

https://gyazo.com/0bfc8af7cf27e89217bd4510895914a2

Share this post


Link to post
Share on other sites
29 minutes ago, Skirmish_ said:

however the line intersects doesn't actually work and i can see the tag through walls:

Because lineIntersect expects ASL positions.

ShowNameTags = addMissionEventHandler [ "Draw3D", {

	{
		_unit = _x;

		_distance = cameraOn distanceSqr _unit;
		_colour = [ 0, 1, 0, 1.5 - ( _distance / ( 12^2 )) ];

		_name = "";
		{
			_name = format [ "%1%2%3", _name, [ endl, "" ] select ( _name == "" ), name _unit ];
		}forEach crew vehicle _unit;

		_unit selectionPosition "head" params[ "_headX", "_headY", "_headZ" ];
		_pos = _unit modelToWorldVisual [ _headX - 0.05, _headY, _headZ + 0.7  + (_distance / ( 12 ^ 2 )) / 1.5 ];
		if ( isNull objectParent _unit && { !( lineIntersects [ AGLToASL positionCameraToWorld[ 0, 0, 0 ], eyePos _unit, cameraOn, _unit ]) } ) then {
			drawIcon3D[ '', _colour, _pos, 0, 1.0, 0, _name, 1, 0.0345, "RobotoCondensed", "center", false ];
		};
	}forEach ( allUnits select { side _x in [ civilian, west, independent ] } );
}];

 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks a lot man, you helped me so much and I learned a lot from this

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

×