After a user requested this in the scripting forum, I put it together. Tought I might put it here for all to see.
Also check this page
http://foxhound-production.com/3dgs/lazersight/lazersight.phpFor a simualr particle effect used as a lazer sight.
entity* model_a;
entity* model_b;
function main
{
level_load("test_level.wmb");
wait(3);
model_a = ent_create("guard.mdl",vector(200,0,0), null);
model_b = ent_create("guard.mdl",vector(-200,0,0), null);
var var_1 = 1;
var i;
i = ent_vertices(model_a);
while(1)
{
var_1 %= i;
var_1 += 1;
particle_line(var_1);
model_a.pan += 1;
model_b.pan += 1;
wait(1);
}
}
function remove_flares()
{
my.lifespan = 0; // remove the flare particle
}
bmap beam = <beam2.tga>;
function particle_function()
{
my.bmap = beam;
my.flare = on;
my.bright = on;
my.size = 10;
my.transparent = on;
my.alpha = 50;
my.function = remove_flares;
}
var vector1[3];
var vector2[3];//local vars so this function can be ran several times at once
var dist;
FUNCTION particle_line(var_1)
{
var temp_array[3];
vec_for_vertex(vector1, model_a, var_1);//we get the vectors of the vertexs
vec_for_vertex(vector2, model_b, var_1);//same here
dist = vec_dist(vector1.x,vector2.x);//we get the distance of the vertexs
//return;
while(dist > 0)//until we are finished with this chain, NO WAIT!!!!
{
vec_set(temp,vector2.x);
vec_sub(temp,vector1.x);
vec_to_angle(temp_array,temp); // now TEMP_ARRAY looks at VECTOR2
temp.x = vector1.x + dist * cos (temp_array.pan);
temp.y = vector1.y + dist * sin (temp_array.pan);
temp.z = vector1.z + dist * tan (temp_array.tilt);//CALUCLATES THE ANGLE
effect(particle_function, 1, temp, normal);//CREATES THE PARTICLE
dist -= 1;//the higher this number the lower the quailty the particle line is, 5 is good
}
return;
}
font standard_font = "Arial",1,20; // truetype font
panel debug
{
flags = visible;
digits = 100,10,4,standard_font,1,vector1.x;
digits = 100,25,4,standard_font,1,vector1.y;
digits = 100,40,4,standard_font,1,vector1.z;
digits = 100,70,4,standard_font,1,vector2.x;
digits = 100,85,4,standard_font,1,vector2.y;
digits = 100,100,4,standard_font,1,vector2.z;
digits = 100,140,4,standard_font,1,dist;
}