Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


Two questions about Collision Detection.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Jode   Members   -  Reputation: 105

Like
0Likes
Like

Posted 18 April 2012 - 02:26 PM

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.
Hobbyist game developer, game designer, and gamer.

Sponsor:

#2 TheResolute   Members   -  Reputation: 187

Like
0Likes
Like

Posted 18 April 2012 - 04:11 PM

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
Researching quadtrees (http://en.wikipedia.org/wiki/Quadtree) could be useful to your for that purpose

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
Otherwise, read this article (http://www.gamedev.n...collision-r2604) and you might be able to apply it to 3D with some thought and possible additional research




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS