Skip to main content
gamedev.net
🔒 Locked

Collision detection

Started by mikael_j 8 replies 600+ views
Original Post
mikael_j
mikael_j
I have some ideas on how to implement collision detection in tile based games, but I figured that I might as well ask everyone around here if you know of any good methods of collision detection (fast and simple (or at least simple)? Any help appreciated.
Tornado
Tornado
How about a bounding box ? It''s the easiest of them all...
You create an invisible box that bounds the object, when this box hits other objects'' boxes, we have a collision!



The road to success is always under construction
Goblineye EntertainmentThe road to success is always under construction
Mezz
Mezz
I''ll second the bounding box idea, your game is tile based so it makes it quite easy to implement the tile sized boxes, then you just may just flag the tile as used so nothing can cross it.

-Mezz
ImmaGNUman
ImmaGNUman
BOOL Collision(RECT obj1, RECT obj2)
{
RECT temp;

if (IntersectRect(&temp, &obj1, &obj2)) return TRUE;

return FALSE;
}

Thats my collision detector.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
mikael_j
mikael_j
Bounding box? Now why didn''t I think of that?
Guess I''ll go with that (and I''m not even going to mention how I was previously thinking of doing it...).
Xeno
Xeno
actually there is some better way (thats what i think )
i learned it from witchlord .

the problem in your why is that u can have a pixel space between the too object andthat means its not a good collusion...
the other why is to create a circle that its origin is the object origin, then , if u want to check if the object collide some other object just check if the sum of the two objects circles radiuses is bigger that the distance between the two circles origins....
hope its help .

u can do the same thing with if u want to check if object collide some point.

"Everything you know is wrong" - Bono
------------------------------- Goblineye Entertainment------------------------------
Arkon
Arkon
hmmm check it out!!!
http://qsoft.cjb.net

tutorials-->dos-->col det..

good luck
Xeno
Xeno
heh , yea arkon have nice tutorial

"Everything you know is wrong" - Bono
------------------------------- Goblineye Entertainment------------------------------
Arkon
Arkon
thanks, soon i''m gonna write a new col det tutorial
for 3d too....
anyway this is enough
LowRad
LowRad
There''s two way, i known to detect collision of 2 object.

The first one as mentionned earlier is BoundingBox, that''s great but it''s a lot of calculations compared to the second option.

The second option is BoundingSphere, where you only store the greatest distance from the origin (0,0,0) to the fartest vertex of your object.

This way, with only : "if (d < ( r1 + r2))" you can known if there a chance that those 2 object will collide.

d : distance between the center of the two object to check for collision

r1, r2 : Is the maximum radius of the 2 object (bounding sphere)

When, in the first or second method, the condition for collision return TRUE, that dont mean that those objects has collide; But instead, that those object has a chance to collide.

So when you detect a potiential collision, you must check each polygon of each object to see if they''ve really collide together.

I must say, that collision detection is a costly function. So, as always there''s some room for improvement. Instead of checking, each polygons of each object together, after detecting a potential collision, why not have a tree of bounding sphere or bounding box for each object.

So let say that we have two persons running toward each other. So when the two are coming closer, the first BoundingSphere will return true as if they where collide, but in fack they may be at 2 meters. So, when the head node of the BoundingSphere tree return true, we go a step down. So, now we have a boundingsphere for the torso, each legs, arms, ...

With this type of Collision Detection, you can achieve very, if not perfect, collision detection. At less cost, then boundingbox alone, without CollisionTree.


That was only my reflection of the Collision Detection part of an Engine. Let try it now !!

Happy Coding,

LowRad

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.