Help Creating Dynamic Particle Speed Along Y Axis

R

r3vdev

Guest
Hello GM Community,

So i created the following particle effect following some youtube guides:

//// Light Beam Noise System
lbeamNoiseSystem = part_system_create();

//// Light Beam Particles
lbeamNoise = part_type_create();
part_type_shape(lbeamNoise, pt_shape_line);
part_type_size(lbeamNoise, 0.1, 0.2, 0, 0);
part_type_color2(lbeamNoise, c_white, c_white);
part_type_alpha2(lbeamNoise, 0.5, 0.01);
part_type_gravity(lbeamNoise, 0.1, 180);
part_type_speed(lbeamNoise, 0.5, 0.5, 0, 0);
part_type_direction(lbeamNoise, 180, 180, 0, 0);
part_type_orientation(lbeamNoise, 180, 180, 0, 0, 0);
part_type_life(lbeamNoise, 20, 180);

//// Light Beam Noise Emitter
lbeamNoiseEmitter = part_emitter_create(lbeamNoiseSystem);
part_emitter_region(lbeamNoiseSystem, lbeamNoiseEmitter, 0, room_width-100, 0, room_height, ps_shape_rectangle, ps_distr_linear);
part_emitter_stream(lbeamNoiseSystem, lbeamNoiseEmitter, lbeamNoise, 5);​

What I would like to do is create a dynamic speed gradient along the Y axis. So particles flow faster at the center Y point of the view, and then gradually slow towards the top y and bottom y value of the view.

Does anyone have any ideas on how to approach this?

Thanks!
 
N

NoFontNL

Guest
You could use quadratic functions.

This line is: y=-0.5*(x^2)+0.5*x+0.375
upload_2019-6-28_15-17-56.png
ANY point on this line, the speed is gonna be the y's position (peak 0.5)
The x position determines the in-game y position relative to the room height.

Example:
Code:
_pos=y/room_height; // Center of room is 0.5 (peak in image)
// Top or bottom will return a number close to 0 or 1.
spd = -0.5*(_pos^2)+0.5*_pos+0.375; // Now we have the position, we only have to put it in the formula and we're done!
// The _pos variable is actually the X position in above image, and we calculate the Y position in the image. 
part_type_speed(lbeamNoise, spd, spd, 0, 0);
// Now you set the speed.

// If you use views, you have to change the _pos calculation.
// That will be _pos=(y-view_yview) / view_hview
 
Top