This project has moved and is read-only. For the latest updates, please go here.

What's the best way to tell if the space between two bodies is clear?

May 7, 2010 at 7:49 AM

I'm programming some rudimentary AI and I want to be able to tell if the path between two spheres is clear of other bodies or not. I've been thinking of constructing a rectangle body that covers the path from the source to the destination and testing to see if it collides with anything in the system. Is there an easier way? I am pretty new to this stuff.

May 7, 2010 at 1:42 PM

Raycasting should do the trick. The problem using a rectangle is that you have to wait to the following step to see if it is colliding with something (I think, not sure).

May 8, 2010 at 7:36 AM

Maybe this is where my ignorance is going to show through. I'm not sure how to do ray collisions. I've been testing all my objects against mouse clicks using Geom.Collide(Vector2), and letting the simulator handle all of the other collisions (things bouncing off of each other) 

Do I need to create a geom for the ray and pass that to Geom.Collide()? Or is there another collision test method I use to test the rays? I read through the collision detection part of the manual @ but i'm still not quite sure how to proceed.

May 11, 2010 at 5:13 AM

once I started digging around for raycasting, I found this That's basically the exactly same situation I'm in. I'm working on the rectangle solution to see how it goes.

May 11, 2010 at 6:33 AM

Looks like Rayhelper.cs contains all the methods you need.

May 11, 2010 at 8:02 AM

Ooops, sorry for the delay on the answer. Yep, the rayhelper should work for you. Look in the discussions how it works, basically you trace a line between two points and it returns you the geoms and the points where this line (the ray) intersects :)