GML Particle facing changes mid-motion?

Discussion in 'Programming' started by Sixmen, Apr 25, 2017.

  1. Sixmen

    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!
     
  2. Neptune

    Neptune Member

    Joined:
    Jun 21, 2016
    Posts:
    1,069
    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.
     
  3. Joshua Allen

    Joshua Allen Member

    Joined:
    Jun 20, 2016
    Posts:
    46
    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);
     
  4. Sixmen

    Sixmen Guest

    Thank you Joshua! Works like a charm, although I'm not sure why.
     
  5. Joshua Allen

    Joshua Allen Member

    Joined:
    Jun 20, 2016
    Posts:
    46
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice