Archived

This topic is now archived and is closed to further replies.

Best ways to test for collision detection.

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

Recommended Posts

[removed] [Edited by - DevLiquidKnight on February 14, 2007 9:21:15 AM]

Share on other sites
If you want a working implementation of a collision detection system to see what you would like, try Paul Nettle''s ellipsoid collision scheme.

http://www.fluidstudios.com/publications.html

That seems to be very effective. Spheres are easier to implement though.

Share on other sites
try coldet:

www.photoneffect.com/coldet

Share on other sites
Just use the distance equation,

Private Function GetDist(intX1 As Single, intY1 As Single, intX2 As Single, intY2 As Single) As Single

DIST = Sqr((intX1 - intX2) ^ 2 + (intY1 - intY2) ^ 2)

End Function

Private Sub Colision()
If Dist(Object1, Ojbect2) >= 0 Then

'' perform collision repsonse code

Else
Exit Sub
End If

If you are using 3D, the dist equation is

Sqr((intX1 - intX2) ^ 2 + (intY1 - intY2) ^ 2) + (intZ1 - intZ2) ^ 2)

-megaman

Share on other sites
Two problems with distance equasion technique: a) works only if you''re testing if two points collide. Might be better if you could check for a range. That would give you a point within a sphere test, which is a little better. b) it''s slow. You''ve got 2 multiplications two substractions and a square root. For normal loads that''s probably fine, but not when you''ve got a good deal of collidable objects on screen.

A simple InRect call is fine for a simple 2D engine, especially if your sprites take up an entire rect. This can be most simply implemented as (in C):

  inline bool IsInRect(int x, int y, RECT rect){     return x > rect.left && x < rect.right &&            y > rect.top && y < rect.bottom;}

Also, if you''re working with a tile engine with unmovable tiles, flaging tiles you can''t walk on is a simple check. e.g. map[x][y].isWalkable

Share on other sites
inline bool IsInRect(int x, int y, RECT rect)
{ return x > rect.left && x < rect.right && y > rect.top && y < rect.bottom;
}
is somthing i never seen before quite intersting

Share on other sites
Most engines when you collide with a wall at an angle you move slowly parralel to the wall. If you get what i mean - in my engine you stop dead - i wanted to have that slow parralel movement - what algoritm is that.

YOU''''LL NEVER BEAT THE IRISH!

Share on other sites
quote:
Original post by Cuchulainn
Most engines when you collide with a wall at an angle you move slowly parralel to the wall. If you get what i mean - in my engine you stop dead - i wanted to have that slow parralel movement - what algoritm is that.

Just project the velocity vector onto the surface. My linear algebra is a bit rusty bit I think it''s:

v is the velocity vector, w1 and w2 are any two non-parallel vectors on the plane. The projection of v onto the plane is (v dot w1)/(w1 dot w1)*w1 + (v dot w2)/(w2 dot w2)*w2