iDevGames Forums
Help with Collision Detection..(i'm almost there) - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Help with Collision Detection..(i'm almost there) (/thread-9115.html)

Help with Collision Detection..(i'm almost there) - carmine - Jun 29, 2011 10:43 AM

I've been working from different sources on the web and I'm almost there.

I have some animated models. I'm calculating the Bounding Sphere and AABB (for each frame) and storing it.

When I move an object I store it's old position, then...
- Do a Sphere collision test.
- If that hits... I rotate the AABB and then make a new AABB from the 8 corners (making a slightly bigger AABB). Then check if that hits.
- If so... put the object to the position it was just in...

This is workingish...problem is, I'm getting objects sort of locked in each others boxes. If I run into an object and then start rotating, my box can expand and we get locked in.

Also, we're not really exactly touching... Anyone have a suggestion on the next step?
- Should I be using some other sort of collision detection?
- Recalculate a new AABB?
- Am I doing something embarrassingly wrong.


Edit: Added screen shot below...
[Image: LHDjZ.png]

RE: Help with Collision Detection..(i'm almost there) - ThemsAllTook - Jun 29, 2011 12:33 PM

(Jun 29, 2011 10:43 AM)carmine Wrote:  - If so... put the object to the position it was just in...

This may be the cause of your problems. For good collision response, you'll generally want to interpolate between the old and new positions to find the closest nonintersecting position and push your object back out only that far, update their velocities as appropriate, then subdivide your timeslice and run collision detection again on the remaining portion.

An example: A moving point is positioned at {0, 0} with a velocity of {4, 2}. There's a solid vertical wall at x=3. If the point moves a full step, it will intersect the wall. In the first 75% of the timeslice, the point does not intersect the wall, so you can interpolate its resulting position to {3, 1.5}. From there, assuming the wall has no friction or elasticity, the point's velocity would be changed to {0, 2}. You'd then process the remaining 25% of the timeslice with the new position and velocity (multiplied by the timeslice fraction), moving the point to {3, 2}.

I hope that's not too confusing. The above is only basic principle and would have to be modified for your particular situation, but maybe it'll at least give you something to go on.