I often want to find the first collision along a ray. It seems like getting all of the collisions along the ray (potentially traversing through a huge number of objects if its pointed level across my map), then sorting them by distance, is a horrible way to do it.
I generally have many thousand collision solids grouped roughly into an oct-tree, and a couple of line segments, rays and sphere (not many) that collide into them. Having a ray “leak” past the first nearby collision and activate oct tree groups all the way down to leaf nodes across the entire map is bad.
Maybe a collision solid, specifically for a first hit ray would be possible? I’d also like to be able to impose a max distance to check (basically a fist hit line segment). To be clear, I’d still expect it to often process several collision points and have to sort them, but if it could skip most of the far away ones most of the time, that would be awesome.
I’ve tried some hacks with line segments guessing how far I might need to look, but thats a pain, and rather inflexible.
Doing several traversals with different line segment lengths until one hits could work, but thats sounds inefficient (if that actually is not too wasteful, then I’ll just implement that) Ex: check from 0-1 meter, then traverse again checking from 1-2, then maybe 2-4 or so up to a max. I’d tune the selection of ranges based on the exact use case.
Is that a good approach?
Example use cases: camera collision, ground collision, mouse picking
In the future, I’ll probably page collision geometry separately from visible so there isn’t any terrain collision really far away, but I still see potential for improvement here.