• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[ RESOLVED ] Using Particle Emitter with length_dir ??

D

Diveyoc

Guest
Does anyone know how to get the x,y, of a particle burst to follow the tip of a gun. I've used this in multiple scenarios with instances, but this is the first time with particles. I've posted what I think is the relevant code below.

The x,y length_dir code I'm using shoots the flame from the tip of the gun. But when I rotate the gun with the mouse, the point of origin of the emitter stays in the same spot. The flames shoot toward my mouse, it's just the point of origin that does not follow the tip of the gun.

Do I need to work this into the part_emitter_region command somehow? Or is there another command I'm missing?

This particle is activated by holding the shift key.

pdir = point_direction(x, y, mouse_x, mouse_y);

x = (obj_flame_thrower.x + lengthdir_x(20, image_angle));
y = (obj_flame_thrower.y + lengthdir_y(20, image_angle));

//==== PARTICLE SYSTEM ====\\
fire_sys = part_system_create();
part_system_depth(fire_sys,-12000);

//==== FIRE PARTICLE LIGHT GLOW BLENDED ====\\
fire = part_type_create();
part_type_sprite(fire, spr_flame, true, false, true);
part_type_size(fire, 0.2, .5, .02, 0);
part_type_alpha3(fire, 1, .8, .4);
part_type_speed(fire, 12, 16, 0, 1);
part_type_direction(fire, pdir-4, pdir+4, 0, 0);
part_type_orientation(fire, pdir-15, pdir+15, 0, 0, false);
part_type_life(fire, 20, 30);
part_type_blend(fire, 1);

//==== PARTICLE EMITTER ====\\
fire_emit = part_emitter_create(fire_sys);
part_emitter_region(fire_sys, fire_emit, x-1, x+1, y-1, y+1, ps_shape_ellipse, ps_distr_linear);

part_emitter_burst(fire_sys, fire_emit, fire, 8);
 
S

siggi

Guest
to make the origin point follow the tip of the gun based on its rotation, you gotta offset it a bit using a handy dandy little nugget of code thats probably to do with trigonometry or something idk maths: create particles at obj_gun.x+=cos(obj_gun.direction*pi/180), obj_gun.y-=sin(obj_gun.direction*pi/180); direction probz being image_angle i think, hope this helps :)

edit: minus the equals signs

edit2: also multiply the whole thingy ie (cos(obj_gun.direction*pi/180))*16 by some number probably the length of your gun :)
 
D

Diveyoc

Guest
Good grief, I looked at this and thought no way I'm getting this to work. I found that I needed to link my obj_flame_thrower image angle instead of direction like you had. Probably because I already have it set up with turret type min/max rotation and angle code.
In any case, I was already using this pdir variable so it worked out pretty sweet. Thanks for the help, here's what worked for me.

pdir = obj_flame_thrower.image_angle

x = obj_flame_thrower.x+(cos(pdir*pi/180))*34
y = obj_flame_thrower.y-(sin(pdir*pi/180))*34
 
S

siggi

Guest
omg the first programming question i ever helped anyone with i feel like a new neckbeard jk np glad i could help :)
 
Top