Jump to content
  • Advertisement

Archived

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

darkzim

collision detection

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been looking at some articles on 2d collision detection, but they all seem to provide a function like this: int CollisionTest(obj1,obj2) { ect,ect. } My question is do I have to call this function like this in my main loop: CollionTest(player,obj1) CollionTest(player,obj2) CollionTest(player,obj3) CollionTest(player,obj4) CollionTest(player,obj5) CollionTest(player,obj6) and so on and so on... that seems like a waste of time..... thanks -darkzim

Share this post


Link to post
Share on other sites
Advertisement
well what are these "objects" you are testing collision against? you can group them togeather in an array or other container, and then do something like this:

for(int j = 0; j < MAX_OBJECTS; j++)
CollsionDetection(player,objects[j]);


[edited by - graveyard filla on June 2, 2004 8:55:54 PM]

Share this post


Link to post
Share on other sites
You have to do something more useful with the function. For example, in your game loop you'd call DoPhysics(). Your DoPhysics() would look like this:

void DoPhysics() {
if (CollisionTest(player,floor)
player.downwordvelocity=0;
if (CollisionTest(player, wall)
player.hurtshimself();
}


If you have a complicated map, you'd probably have a more automated physics system which reads a map from a structure and tests for various types of collisions.

Zorx (a Puzzle Bobble clone)
Discontinuity (an animation system for POV-Ray)

[edited by - clum on June 2, 2004 8:57:21 PM]

Share this post


Link to post
Share on other sites
Yeah, but testing collision agenst EVERY SINGLE THING seems like a waste of power when the player could be 500 feet away from that object.

Share this post


Link to post
Share on other sites
If you have a map, then you can test against only things from nearby tiles.

Zorx (a Puzzle Bobble clone)
Discontinuity (an animation system for POV-Ray)

Share this post


Link to post
Share on other sites
what kind of game are you working with ? usually if you have a tile based game, you wont do bounding box collision with the environment. you would try to find which type of tile the player/npc was colliding with. bounding box still comes in handy for player/npc collision with each other though... also, its not too hard to not check collision if there not on the screen. i know there are special data structures for dealing with this (quad trees and such), but i have a pretty simple way...

my npc''s simply have an On_Screen() function. it returns true if the enemy is on the screen... ill only check collision with an enemy that is On_Screen()...

Share this post


Link to post
Share on other sites
There are ways to reduce the number of tests required by a lot. Divide the map into some bigger regions (even if it''s not a tile-based map), and only check objects against those in their region or in regions adjacent to them. Also, first do a very simple check, like the distance between two objects, and only if that passes, do the full collision test.

Share this post


Link to post
Share on other sites
some other strategies are to only test objects against other objects for which they make sense. Bullets do not (normally) collide with other bullets, for instance. You can segregate all your objects and only compare some groups with other groups.

Another thing you can do is seperate objects into Active and Passive objects. Only test Active (moving) objects against the other objects, but don''t test static "World" objects against the others (they never move so will never hit each other).

Still more, only calculate combinations, not permutations. Check A::B, but not B::A as well.

If you only have a few objects, don''t worry about using a simple list, as it will probably be *faster*. If you have potentially hundreds of objects, you should look into a space partitioning data structure to contain your objects.

Share this post


Link to post
Share on other sites
i was thinking, i have a flamethrower weapon in my game...

currently, i do bounding box collision for each particle that spits out of the flame thrower... a particle is something like 15x15 px big and one is spit out each frame... is it bad to do this? im not going to start optimizing yet, but do you think i should do something like make a bounding box covering the entire flame and check collision against that?

Share this post


Link to post
Share on other sites
For a flame thrower I''d only check to see if objects are in a "hit region" - not the flame particles themselves; ie.

If I''m standing in front of a guy with a flamethrower, I''m in the "hit region".

If he decides to fire it, each object is checked to see if it would be hit. This *should* be faster than if you check each object for each flame particle.


Yes... VB6 is here to steal your minds fps. Very slowly.
Call .optimize(you.sig)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!