# Sphere cuboid collisions - issues with hitting corners

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

## Recommended Posts

Hi, so i posted about this forever ago: http://www.gamedev.net/community/forums/topic.asp?topic_id=435618&whichpage=1� i recently picked this project up again and i'm having issues with it. the help i recieved then was spot on, and spheres can seemingly bounce off the cuboid faces fine (AABB or OBB), but if they hit a corner, they behave abnormally. once i've identified the sphere hits the cuboid, i check which faces it collides with (by representing each face as a plane). i thought if it hits a corner or edge its no problem as it will just be reflected off of two/three planes, but this doesn't seem to work. is it my approach thats flawed or could it be my implimentation? is there a more sensible way to do this?

##### Share on other sites
How so? With the code posted, it should be straight forward to make spheres bounce against any kind of convex surface.

1) find the closest point on the perimeter of the cube / rectangle.
2) bounce the sphere against that point, using the 'velocity reflection' algorithm.

Here is a thread with some example code.

http://www.gamedev.net/community/forums/topic.asp?topic_id=440708

##### Share on other sites
im not sure what was in the code oliii posted, but to find the minimum translational vector for a sphere and box, the best method is to transform the sphere to box coordinates, and see what voronoi region the centre of the sphere is within:

http://denvish.net/ulf/260607/27604_voronoi.jpg

obviously im not showing everysingle one, but the general idea:

the bottom left are the voronoi regions for each face contact, if the sphere centre is within one of them, then the minimum translational vector, and then the point of contact, and normal to use in collision reflection or whatever, is simply the face normal transformed back to world space.

the regions for it colliding with an edge are shown in bottom right, in this event, you can calculate the MTV, and the normal of contact by imagining it as 2D problem by ignoring one dimension and normalising the sphere position in box space.

so if its colliding with the edge running parallel to the z-axis, ignore the z-axis, and normalise the sphere position as if its 'z' component was 0, and that will be the normal for contact to be transformed back into world space from box space.

top right, is the collision with vertex instance, in which case the normal for contact is just the subtraction of sphere position from vertex position.

in the event that the sphere centre is inside the box, then you have the middle case, where it degerates to a face contact depending on which its closest to.

##### Share on other sites
The case of a moving sphere of radius r hitting the corner of a cuboid, is actually the same as the case of a ray hitting a sphere of radius r.
Therefore it's a simple ray/sphere intersection test for the corners![cool]
Similiarly, for the edges it's a ray/cylinder intersection test with radius r.[cool]

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 96
• 11
• ### Forum Statistics

• Total Topics
632974
• Total Posts
3009641
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!