Jump to content
  • Advertisement


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


How to do box-sphere collision detection?

This topic is 5752 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all How to do box-sphere collision detection efficiently? (The box is static and axis-aligned.The sphere is moving) besides, how to adjust the displacement of the moving sphere? (I want sliding effect) Thank you.

Share this post

Link to post
Share on other sites
It is like rectangle and circle.
When checking the collision with circle, use the cohen-sutherland alg. and then check middle of circle with side of rectangle or vertex, dependt on code from alg.
When you don''t understand you can e-mail me and I will write more.
P.S.: sorry for my english

Share this post

Link to post
Share on other sites
An easy trick is to extend the sides of the AABB by the radius of the sphere. This breaks the problem down to a point and a box. This is relatively easy to figure out by checking if the point lays behind all of the sides (plane/point test).

For a moving sphere, you use a line segment (remember we are testing against a point, so linear movement of a point is just a line). Split the line segment when it crosses a box plane. If any line segment left is within the box, you have a collision (and the collision point btw). Look into the BSP algorithm for the splitting of the line segment.

The sliding effect can be accomplished by a simple equation.


Its best to solve a collision by deflecting the players motion rather than stopping at the impact point. Imagine running down a hallway and brushing up against the wall would cause you to "stick". This is easily solved using something in your code like:

Vt += Ni * (-dot(Ni,Vt)-Nd)
Vt = Desired Target or Destination of Player
Ni = Normal to the plane of impact
Nd = The "D" of the hit poly''s "plane equation"
In English, this just means: move the target-position above the impact plane in the direction perpendicular to that plane.

This quote is from http://www.gamasutra.com/features/20010324/melax_01.htm

I haven''t really thought through the problem completely, someone please tell me if I''m wrong here.

Before I couldn''t spell engineer, now I are one!

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!