#### Archived

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

# Collision Detection et al

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

## Recommended Posts

Hullo All, I''m currently in the design process of my first game. It''s a 2d, overhead view, tank adventure ( a remake of Iron tank). I have some questions about collision detection: All of the articles I''ve read define an algorithm that assumes you have two objects that you test for a collision. This is simple enough, but how do you decide which objects to test. You certainly can''t test them all every time, but I can''t think of an algorithm that would work. If it was just unit-unit collision I suppose you could work out something with radii or distances between them or something, but with walls, trees, etc, it gets more difficult. All of the main issues discussed in the collision detection articles that I''ve read are based on trying to maximize efficiency. It seems to me that if you reduced the number of objects that were needlessly tested for a collision that this would increase efficiency. I''m not sure if this makes sense or not. Maybe I''m trying to avoid the slowness of collision detection with more collision detection. Anyway, your thoughts would be most appreciated here. E-mail: chaos1111@hotmail.com or ICQ: 22527985 me if you''d like. -Mark

##### Share on other sites
there are tons of ways to perform collision detection..and yes you can increase efficency by reduceing the number of objects to check against...

first off, assumeing your game map is much larger then what the screen can hold, you can "sub divide" the map into sections [for the sake of simplicity divide it into four sections cutting down the middle] create a linked list of pointers to the objects within each section...then just check against all other units within the same section...there are problems of course [if a unit overlaps the border between sections...but you can check for this and report the unit to all the sections it exists within]...also useing concepts derived from data constructs such as "oct-trees" can help [make the section size baised on a power of 2, and you can left/right shift to calculate what section a unit belongs to...saves from doing division and the CC overhead that uses]

Also you will want to classify units to reduce redundant checking...if player and enemy bullets do not effect each other [ie...the player cannot shoot the bullets fired from the bad guys] then there is no reason to check if bullets collide...all you need is a "class system"...something like: "I hit bad guys", "I hit player", etc.. then when you spawn a bullet, enemy, etc.. simply "register" it with the associated class...you can then perform the checks in question only on the objects that actually have an effect on it...

Another way to help is to keep a active list containing only the objects that are within viewable range [this will also help speed up drawing things to the screen, etc]...these potentualy viewable objects can be updated every frame...while all the others can be updated every ten frames or so [and moveing them 10 times the distance, etc..] this will help by reduceing the time you would spend on AI routines for each object, etc..

good luck

• 16
• 9
• 13
• 41
• 15