Ok I have managed to make this code which seems to do what I need:
ENTITY* gun1;
ENTITY* gun2;
function p_alphafade(PARTICLE *p)
{
p.alpha -= p.skill_a*time_step;
if (p.alpha <= 0) p.lifespan = 0;
}
function p_trace(PARTICLE *p)
{
set(p, BRIGHT|TRANSLUCENT|BEAM);
p.size = 1;
p.skill_a = 20; // fade factor
p.event = p_alphafade;
p.red =255;
p.blue=20;
p.green=128;
}
action tracer_right()
{
VECTOR last_pos;
while(1){
vec_set(last_pos,my.x);
my.z +=1.5;
my.y +=2;
if (my.y>1){break;}
effect(p_trace,1,my.x,vec_sub(last_pos,my.x));
wait(1);
}
}
action tracer_left()
{
VECTOR last_pos;
while(1){
vec_set(last_pos,my.x);
my.z +=1.5;
my.y -=2;
if (my.y<-1){break;}
effect(p_trace,1,my.x,vec_sub(last_pos,my.x));
wait(1);
}
}
function main()
{
vec_set(sky_color,vector(0,0,0));
level_load(NULL);
video_window(NULL,NULL,0,"Laser demo");
vec_set(camera.x,vector(-250,0,50));
vec_set(camera.pan,vector(0,-15,0));
while (1){
if (mouse_left == 1){
gun1=ent_create(NULL,vector(-100,-170,-80),tracer_right);
gun2=ent_create(NULL,vector(-100,170,-80),tracer_left);
}
//if(proc_status(tracer_right) == 0){ent_remove(gun1);}
//if(proc_status(tracer_left) == 0){ent_remove(gun2);}
wait(1);
}
}
However the entities need to be destroyed otherwise after a couple of fires they will cause an error. I tried using the commented lines in the main function but they causes errors.
Last edited by Ercoles; 12/13/12 17:11.