• Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!

GML Particle facing changes mid-motion?

S

Sixmen

Guest
Hello!

I've set up a particle system for bullet trails. Every time I click the mouse, a bullet is created which moves towards the mouse. Particles shaped like white lines are created at the bullet object per step, creating a nice trail effect. The problem is that I have set the particle orientation to match the bullet direction.
If I shoot straight it looks fine.

Like this: - - - - - - -

The problem is when I move the mouse around and shoot at random directions the orientation of the particles change mid-motion.

Like this: - - - - / / /

I'm guessing the new particles created at the end of the bullets lifespan take their orientation from the new bullets instead of the original one. Any way to prevent this and make the orientation stay the same throughout the bullets lifespan?

The create event for the bullet looks like this:
Code:
image_angle=point_direction(x,y,mouse_x,mouse_y);
//Create system
ps = part_system_create();
//Run script
scr_part_ptrail_init();
//Create emitter
pe = part_emitter_create(ps);
part_type_orientation(global.pt_ptrail,self.image_angle,self.image_angle,0,0,true);
alarm[0]=30;
move_towards_point(mouse_x,mouse_y,20);
The step event for the bullet looks like this:
Code:
part_emitter_region(ps,pe,x,x,y,y,pt_shape_pixel,1);
part_emitter_stream(ps,pe,global.pt_ptrail,1);
I would appreciate any input on the matter.
Thank you!
 

Neptune

Member
You could try skipping using an emitter, and use part_particles_create()... Although the more i think about it, im unsure how you could have different angles for each bullet.
 
Try changing your step event to:
Code:
part_type_orientation(global.pt_ptrail, image_angle, image_angle, 0, 0, true);
part_particles_create(ps, x, y, global.pt_ptrail, number);
 
S

Sixmen

Guest
Try changing your step event to:
Code:
part_type_orientation(global.pt_ptrail, image_angle, image_angle, 0, 0, true);
part_particles_create(ps, x, y, global.pt_ptrail, number);
Thank you Joshua! Works like a charm, although I'm not sure why.
 
It's because global.pt_ptrail is a pointer to the data the makes up the particle. Whenever you create a new particle, a copy of that data is added to a particle system. Each time a new bullet was being created it would change the global.pt_ptrail data so every new copy of global.pt_ptrail would use the new data. All my code is doing is changing the data before a particle is copied.
 
Top