Jump to content
  • Advertisement
Sign in to follow this  
Astra

Simple Collision Detection Issue

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

Hi guys. I'm writing a 3D game, similar to Super Smash Bro's the characters only move along the X and Y axis, so I'm doing my collision detection only on the X and Y; and ignoring Z axis collisions.
I tried implementing an AABB method of collision detection but I think I got it a bit wrong. I'm testing the min.x min.y of my character against the min.x min.y max.x max.y of the ''stage'' (that is, one big platform and 3 suspended platforms). So as you would expect only when the bottom left front corner (min) of my "character" rectangle goes into the platform does a collision occur.

What I want to know is if there's a more efficient way of doing it than checking each individual vertex with the platform min/max.

Heres the code for my collision function:

void checkCollision()
{
if((Character1.min(0) > mainStage.min(0)) &&
(Character1.min(0) < mainStage.max(0)) &&
(Character1.min(1) > mainStage.min(1)) &&
(Character1.min(1) < mainStage.max(1)))
{
exit(0);
}
if((Character1.min(0) > platform1.min(0)) &&
(Character1.min(0) < platform1.max(0)) &&
(Character1.min(1) > platform1.min(1)) &&
(Character1.min(1) < platform1.max(1)))
{
exit(0);
}
if((Character1.min(0) > platform2.min(0)) &&
(Character1.min(0) < platform2.max(0)) &&
(Character1.min(1) > platform2.min(1)) &&
(Character1.min(1) < platform2.max(1)))
{
exit(0);
}
if((Character1.min(0) > platform3.min(0)) &&
(Character1.min(0) < platform3.max(0)) &&
(Character1.min(1) > platform3.min(1)) &&
(Character1.min(1) < platform3.max(1)))
{
exit(0);
}
}


and in my character and platform class:

float Character::min(int index)
{
float minimum[3] = {xpos-5.0f, ypos-10.0f, zpos-0.02f};
return minimum[index];
}
float Character::max(int index)
{
float maximum[3] = {xpos+5.0f, ypos+10.0f, zpos+0.02f};
return maximum[index];}



float Block::min(int index)
{
float minimum[3] = {getxCoords()-(getxWidth()/2), getyCoords()-(getyHeight()/2), getzCoords()-(getzLength()/2)};
return minimum[index];
}
float Block::max(int index)
{
float maximum[3] = {getxCoords()+(getxWidth()/2), getyCoords()+(getyHeight()/2), getzCoords()+(getzLength()/2)};
return maximum[index];
}


thanks for any advice

Share this post


Link to post
Share on other sites
Advertisement
Looks like you should get a book on C++ ..

Look into member variables for your character/platform classes..

and do something more generalized with your collision checking..

like:

bool CheckAABBCollision(AABB one, AABB two)
{
if(one.minX < .......
.
.
.
)
return true;

return false;
}

Share this post


Link to post
Share on other sites
i've got member variables, xpos, ypos, zpos. Not sure what specifically i should change about the way i've accessed the variables?

also with the code you suggested, as i've seen in many tutorials - i dont understand AABB one and AABB two. Is this psudo code for my character1. and mainstage? or are there actual commands known as AABB?

thanks for your patience

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!