# Two questions about Collision Detection.

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

## Recommended Posts

First of all, the code.
 bool Positionable::intersectsWith(Positionable other) const { if ((position.x + size.x >= other.getPosition().x) && (position.x <= other.getPosition().x + other.getSize().x) && (position.y + size.y >= other.getPosition().y) && (position.y <= other.getPosition().y + other.getPosition().y) && (position.z + size.z >= other.getPosition().z) && (position.z <= other.getPosition().z + other.getSize().z)) { return true; } else { return false; } } 
Positionable is a class that has a position, a size, and a rotation (all of which are of another class called Vector3).

Questions:
a) I've heard that when you start adding lots of objects, this method of collision detection will slow down the game drastically. Is that true? Does anyone have a better method?

b) How would I have this account for the rotation as well? The rotation is stored as 3 angles, one for each axis.

Thanks.

##### Share on other sites
Yes, it is due to the fact that collision checking happens exponentially in relation to the number of objects you're dealing with
You could partition the entire area in which objects exist that need collision checking into several regions and have objects only check for collisions with other objects in their same region
That will drastically reduce the amount of collision checking you do, assuming your objects are moderately distributed throughout your area

As far as rotation goes, you will have to use a slightly complicated algorithm that basically checks the distance between all the points for each object when aligned to several axis based on each of the edges of your objects
If it would be acceptable to have a bit less accurate collision detection algorithm, you should really consider merely checking the distance between two objects, which is basically encasing each in a sphere and determining whether or not those intersect
In 2D, it's as simple as: if (object0.x - object1.x) * (object0.x - object1.x) + (object0.y - object1.y) * (object0.y - object1.y) < (object0.collisionRadius + object1.collisionRadius) * (object0.collisionRadius + object1.collisionRadius) there's a collision

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632959
• Total Posts
3009476
• ### Who's Online (See full list)

There are no registered users currently online

×