{"by":"don_shadaman","descendants":9,"id":34210305,"kids":[34228005,34229327,34217845,34222798,34217811,34224679],"score":59,"text":"Heya.<p>I created a flexible collision engine for broad detection in C that&#x27;s also pretty fast. Personally that&#x27;s my best, so I wanted to show it here. Although... still not as fast as DragonEnergy&#x27;s one that supposedly handled millions of agents bouncing off each other every frame on an old i3, haha. I hope I get better at this! He set the bar pretty high for me.<p>I was considering including some small function that tries finding the nearest entity, although I think it might be better to simply use query for that matter. Perhaps in the future I will get a good idea of how to do that more efficiently.<p>This is not a clickbait. Although generally you also call other functions in a tick, a collision check between 500,000 circles (&quot;circles&quot;, not &quot;squares&quot;, because distance is checked and forces are applied based on the angle between) is done below 5ms on not really that demanding hardware. I achieve lower times than that on my budget laptop, slightly more on my PC (yeah, weird). The total time spent in a tick is 3-4 times that.","time":1672603734,"title":"Show HN: Detecting collision between 500k circles below 5ms","type":"story","url":"https://github.com/supahero1/hshg"}