• Advertisement
Sign in to follow this  

Sphere cuboid collisions - issues with hitting corners

This topic is 3957 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, 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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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]

I can't find the brilliant article I read about this many years ago, however it worked great for me at the time.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement