|
3 registered members (Grant, vince, 1 invisible),
4,322
guests, and 17
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Need a laser beam particle effect example
[Re: Uhrwerk]
#413416
12/13/12 16:38
12/13/12 16:38
|
Joined: Apr 2011
Posts: 75 Malta
Ercoles
OP
Junior Member
|
OP
Junior Member
Joined: Apr 2011
Posts: 75
Malta
|
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.
|
|
|
Re: Need a laser beam particle effect example
[Re: Ercoles]
#413417
12/13/12 17:10
12/13/12 17:10
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Excellent work. And you did it all by yourself. :-)
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Need a laser beam particle effect example
[Re: Uhrwerk]
#413418
12/13/12 17:13
12/13/12 17:13
|
Joined: Apr 2011
Posts: 75 Malta
Ercoles
OP
Junior Member
|
OP
Junior Member
Joined: Apr 2011
Posts: 75
Malta
|
Thanks
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:15.
|
|
|
Re: Need a laser beam particle effect example
[Re: Ercoles]
#413420
12/13/12 17:17
12/13/12 17:17
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
What error do these entities cause?
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: Need a laser beam particle effect example
[Re: Ercoles]
#413425
12/13/12 19:15
12/13/12 19:15
|
Joined: Apr 2011
Posts: 75 Malta
Ercoles
OP
Junior Member
|
OP
Junior Member
Joined: Apr 2011
Posts: 75
Malta
|
I have solved it by using this in the fire loop:
if(proc_status(tracer_right) < 5){gun1=ent_create(NULL,vector(-100,-170,-80),tracer_right);} if(proc_status(tracer_left) < 5){gun2=ent_create(NULL,vector(-100,170,-80),tracer_left);}
This way it is not causing the error so often(only rarely). But do I still need to kill the entities created or particle entities die by themselves?
I added these lines instead of the commented ones but do not seem to make much difference:
if(proc_status(tracer_right) == 0){ptr_remove(gun1);} if(proc_status(tracer_left) == 0){ptr_remove(gun2);}
Last edited by Ercoles; 12/13/12 19:20.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|