Particle bounce help

I have a particle fountain based on:

it works fine, I just need the particles to bounce, I assume it’s something like

if (y<0)  
y = -y  

but I’m having trouble with where it should go. Any help is appreciated.

Hi Dexter,

I don’t know how your particle system is implemented, but I normally work with a velocity and a position (and acceleration, but let’s leave that out of the picture for now). So in the particles’ update, you have something like

pos += vel;  

If you’d like your particles to bounce at the bottom, you have to invert the y-velocity when the particle hits the floor. (Remember: 0,0 is top left so the floor is at y = ofGetHeight())

pos += vel;  
if(pos.y >= ofGetHeight()){  
    vel.y *= -1;  

You can do this for other sides as well, just invert vel.x when the particle hits the left or right side of the screen and invert vel.y when it hits the top or bottom.

Thank you heaps, it worked, I added your lines of code to Particle::update() and it’s working.

Really can’t thank you enough.