Page 1 of 1

HardonCollider and ray collisions

Posted: Fri Jul 08, 2011 6:49 pm
by pudding
Hello!

I want to "fire" a ray from one set of co-ordinates to another set of co-ordinates and detect whether there is a collision along the length of the ray and if so, where that collision has occurred. The number of objects that could potentially collide with the ray number in the low hundreds.

I know HardonCollider fortunately has the handy "function shape:intersectsRay(x, y, dx, dy)" to test for a collision with a particular shape; my question is: is iterating through all of the potential objects which might collide with the ray the best way of doing this or am I just being an idiot and there's a much better way?

Re: HardonCollider and ray collisions

Posted: Fri Jul 08, 2011 8:59 pm
by bartbes
It depends on how you structure your data, if it's just a plain array, then it's probably the only way. Using a tree could speed up the process, but also make the implementation harder, and I'm sure somebody else here will be able to give you another way to store your data that's more efficient, in the end it's just a matter of how much work you do beforehand.