Jump to content
  • Advertisement

Archived

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

Shooter

Collision detection (bounding box)

This topic is 5860 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

Hello, I am currently writing a collision detection for my 3d game. Unfortunately, it does not work; Sometimes it does not recognize collisions. I think that the problem should be within the following lines (the y coordinates are ignored right now!). Any idea what went wrong? Thanks in advance! bool GfxEngine::BoxesTouch(const BOUNDINGBOX* box1, const BOUNDINGBOX* box2) { bool bHaveTouched=false; if(((box2->minx >= box1->minx) && (box2->minx <= box1->maxx) && (box2->minz >= box1->minz) && (box2->minz <= box1->maxz) && (true)) || ((box2->minx <= box1->minx) && (box2->maxx >= box1->minx) && (box2->minz <= box1->minz) && (box2->maxz >= box1->minz) && (true))) bHaveTouched=true; //Wert zurückgeben return bHaveTouched; } I don''''t need any signature ;-)

Share this post


Link to post
Share on other sites
Advertisement
You are better off checking if the boxes are *not* intersecting:

if(box1->maxx < box2->minx || box2->maxx < box1->minx)
return no_hit;
if(box1->maxz < box2->minz || box2->maxz < box1->minz)
return no_hit;

return hit;

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!