Here's a tip on collision detection
I worked out this algorithm last night which works really well, and I thought I'd share it with you guys. 
Here's the pseudo-code:
This is for a rigid body bouncing off another rigid body (E.G. a super bouncy ball hitting a wall).
The reason why I find it better than my old method (which was using a simple "if overlap, change direction" scheme) is that it prevents false positives from occurring. False positives are what often lead to objects getting stuck.

Here's the pseudo-code:
Code:
BOOL animateAndReportWhetherCollisionOccurred() {
advanceOneFrame();
if (shapesOverlapEachOther()) {
rewindOneFrame();
changeVelocityAsAppropriate(); // could be a simple reflection
advanceOneFrame();
return YES;
}
return NO;
}This is for a rigid body bouncing off another rigid body (E.G. a super bouncy ball hitting a wall).
The reason why I find it better than my old method (which was using a simple "if overlap, change direction" scheme) is that it prevents false positives from occurring. False positives are what often lead to objects getting stuck.
That's what they do in this article. (1.9MB pdf)
Good read, but can anyone figure out their impulse equations? For the life of me I can't figure out how to get frictional impulses to work.
BTW: Can't say I've ever seen pseudo code written with C syntax.
Good read, but can anyone figure out their impulse equations? For the life of me I can't figure out how to get frictional impulses to work.
BTW: Can't say I've ever seen pseudo code written with C syntax.
Skorche Wrote:Can't say I've ever seen pseudo code written with C syntax.
What can I say? I have a fetish for semicolons and curly brackets.
Thanks for the link! I'm no physics major, so it's going to take me quite a while to decipher all of the symbols they use in their equations. Nevertheless, judging from the portions of the paper which I do understand, it looks like exactly the type of info I'm after ATM.
Also, knowing that these guys suggest using the same algorithm I proposed in the parent gives me confidence in my code.
I'm no 3D expert, but when I wanted to add some collision detection functions to my game engine I just looked up the equation for a ray intersecting a triangle in 3D space.
The ray is defined as two points, so I give it the start point and end point of the player (before and after he moved during that iteration), then the equation returns the exact point of collision. Since rays are infinite in one direction, I just add a simple check at the end to make sure the two points are indeed long enough to intersect the triangle.
That algorithm would work even if the object was going so fast that it passed completely through the wall during that iteration.
The ray is defined as two points, so I give it the start point and end point of the player (before and after he moved during that iteration), then the equation returns the exact point of collision. Since rays are infinite in one direction, I just add a simple check at the end to make sure the two points are indeed long enough to intersect the triangle.
That algorithm would work even if the object was going so fast that it passed completely through the wall during that iteration.
imikedaman Wrote:I'm no 3D expert, but when I wanted to add some collision detection functions to my game engine I just looked up the equation for a ray intersecting a triangle in 3D space.
That works fine for particles, but you need something more robust for rigid bodies.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Optimize the collision detection | alaslipknot | 1 | 308 |
May 12, 2013 08:02 PM Last Post: SethWillits |
|
| Collision detection tutorial | ThemsAllTook | 7 | 18,417 |
Nov 5, 2011 05:20 PM Last Post: SethWillits |
|
| Help with Collision Detection..(i'm almost there) | carmine | 1 | 3,519 |
Jun 29, 2011 12:33 PM Last Post: ThemsAllTook |
|
| Time Delta, collision detection | mk12 | 19 | 12,867 |
Sep 8, 2010 06:40 PM Last Post: AnotherJake |
|
| Collision detection for pinball game | johncmurphy | 0 | 3,701 |
Sep 6, 2009 02:46 PM Last Post: johncmurphy |
|

