This topic is now archived and is closed to further replies.


Ray/Sphere collision detection

Recommended Posts

Okay, don''t think I''ve seen this one out here before. Hope someone can help me. First of all: the question. Given a ray and a sphere, how can I tell if they are intersecting? "Ray" is a vector with a normal showing direction, "Sphere" is a vector and a radius. Now, to clarify, the problem: In my litle engine (if you could call it that) I have a fairly nice landscaping techniqe set up for what I hope will end up being a turn based RPG (think FF Tactics for the computer on hexagon shaped maps). Anyways, this routine dose a great job of rendering the land but now I need some way of telling my guys where to go. The most obvious answer is click on a point and have the character move there. I can handle pathfinding and such but I need to know what point the user is clicking on first. My idea was for each point on the map make a sphere around it with a radius of 10 or so. I calculate a ray going straight "into" the world from the screens current rotation and mouse position (which I''m pretty sure I can do). Then I see if the ray is intersecting any of the points "spheres" and move my little guy to that point. I just need to know if the sphere and ray are intersecting and I can do the rest. Anyone happen to have a good equation lying around? ----------------------------- Blue*Omega (Insert Witty Quote Here)

Share this post

Link to post
Share on other sites