#### Archived

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.

## 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 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 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.

quote:

Sliding
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)
Where:
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!

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632997
• Total Posts
3009791
• ### Who's Online (See full list)

There are no registered users currently online

×