Jump to content
Jonssonsson

drawLaser between two objects

Recommended Posts

Hi,

 

I'm trying to create a laser beam that is visible without NV/thermal between two objects. The first object (object_1) is stationary and also the source of the laser beam. My second object (object_2) is a moving object (a unit).

 

I was able to create a laser beam facing north from object_1 with the script below, but I do not know how to set the direction of the laser beam to my object_2. Anybody know how to do this?

addMissionEventHandler ["Draw3D", { 
 drawLaser [ 
  [getPosASL object_1 select 0, (getPosASL block_1 select 1), (getPosASL block_1 select 2) + 1], 
  [0,1,0], 
  [1000, 0, 0],
  [], 
  10, 
  10, 
  -1, 
  false 
 ]; 
}];

 

Share this post


Link to post
Share on other sites
11 hours ago, Jonssonsson said:

but I do not know how to set the direction of the laser beam to my object_2

vectorFromTo

_dir = getPosASL object_1 vectorFromTo ( getPosASL object_2 );

 

  • Like 2

Share this post


Link to post
Share on other sites

Exactly what @Larrow said except i would change getPosASL for getPosASLVisual which gives you much smoother movement and visually precise position (getPosASL runs in simulation scope and getPosASLVisual runs in render scope)
Example code:

addMissionEventHandler ["Draw3D", {  
 drawLaser [  
  getPosASLVisual object_1,  
  getPosASLVisual object_1 vectorFromTo getPosASLVisual object_2, 
  [0, 0, 1000], // Bright blue  
  [],  
  0.5,  
  2,  
  -1,  
  false  
 ];  
}];

 

  • Like 3

Share this post


Link to post
Share on other sites

Thanks guys! I got it working to my requirements with this:

addMissionEventHandler ["Draw3D", { 
 drawLaser [ 
  getPosASL object_1, 
  getPosASLVisual object_1 vectorFromTo [getPosASLVisual object_2 select 0, (getPosASLVisual object_2 select 1), (getPosASLVisual object_2 select 2) + 1], // This only to get the laser beam to hit the object in the middle, not on ground level
  [1000, 0, 0],
  [], 
  10, 
  10, 
  -1, 
  false 
 ]; 
}];

 

Share this post


Link to post
Share on other sites
13 hours ago, Jonssonsson said:

vectorFromTo [getPosASLVisual object_2 select 0, (getPosASLVisual object_2 select 1), (getPosASLVisual object_2 select 2) + 1]

 

vectorFromTo ( getPosASLVisual object_2 vectorAdd [0,0,1] )

Nothing wrong with what you wrote, just pointing out something that is easier to write/read.

  • Like 2

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

×