Closed redblobgames closed 1 year ago
Please fix this
It looks like it's fixed in the JS https://github.com/hunar4321/life_code/blob/main/particle_life.html#L163
The current code doesn't seem to do the right thing. It "resets to the wall" (Setting to zero and width/height at boundaries) and that creates some interesting and unusual artifacts near the border- which are more pronounced if you only use one "color" and a small number of atoms. Understandably, as the velocity vector increases- so does the strangeness. I think resetting to the "reflected" state (as pointed in the code by @redblobgames) is the better approach to minimize these effects.
Fix added and also x4/5 times performance improvement for JS version - https://github.com/hunar4321/particle-life/pull/27
bounds checking fixed for C++ too
The current JS code and the C++ code too are checking
This is not enough to keep the particles inside the box. You can test this by checking how many are inside the box:
The reason is that it reverses the velocity but doesn't apply right away, so the next update the velocity might change to be the wrong sign again. To ensure they stay inside the box you need to have them bounce on this frame and change the velocity, like this:
With this code, the particles all stay inside the box. They might get be pushed out to the outer edges of the box but at least all of them stay on screen.