Making particles collide with water

Is there a way to make particles hit water as well?

I can’t think of anything besides tracing down every frame on each particle’s think function, but that might get slow with a lot of particles. Otherwise, traces are cheap. Have you tried this yet?

Well its a raining effect so there are a lot of particles.

Do a trace once then just wait until the particle hits the correct Z position.

You could calculate its lifetime based on the distance between it and the body of water. You’d need to do a trace for the particles every time they’re spawned, though.

Yeah! That’s a good idea, I totally forgot water is just a brush volume. So you could get all the water volumes on the map and do collisions by comparing the coordinates of each particle to the bounds of each volume. I think you’d have to check x and y too, but just once. And z checks can be replaced by setting the dietime like Yobdren said.

This only really works if the particles are moving straight down though.

No? Just do one trace when the particle has just spawned. Get its velocity angle and trace downwards from that to predict where it will land. Then store that value and in each think function compare your Z value with the stored one on each particle. If your particle accelerates look up some basic physics functions to predict how much time it will take to reach that distance then just compare time until the particle needs to die.

Yeah, you’d have to do a trace once if its not going straight down. Actually, since its rain, you probably should do a trace anyway so you can know when the particle should die and probably play some sort of splash effect based on the geometry below. This should be faster than having particles that collide with things (if you think about it, if you enable particle collisions its like the engine is doing a trace for that particle every frame anyway).

So maybe something like:

Trace along velocity direction like you said
Divide the trace result distance by the particle’s speed (which hopefully is constant D:) to get its dietime
Maybe store the hit normal and the type of surface and other things so you play the right effect when it dies
Send the particle on its way

If it accelerates though I think it would be better to do collisions each frame than predicting (Source does acceleration discretly, so any prediction based on a continuous model won’t be the same. It’s like the difference between doing numerical integration and finding the antiderivitave, if you’ve taken calculus).

One problem though is that tracing once won’t work for moving objects like props, so any prop house you build won’t shelter you from the rain.

Could someone give me an example on how to do this? since i have no idea on how to check when its at the correct Z value.