# Error with collision function

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

## Recommended Posts

Hi guys, I've been coding in a collision function. Its fairly simple stuff, but I've run into an error, and I can't understand why. The function is this:
bool CheckCollision(float Onex,float Oney,float Onez, float Twox,float Twoy,float Twoz)
{
xcheck=false;
ycheck=false;
zcheck=false;

// Make a box from first object vars
BoxOne[1]=Onex;
BoxOne[2]=Onex+10;
BoxOne[3]=Oney;
BoxOne[4]=Oney+10;
BoxOne[5]=Onez;
BoxOne[6]=Onez+10;
// Make a box from second object vars
BoxTwo[1]=Twox;
BoxTwo[2]=Twox+10;
BoxTwo[3]=Twoy;
BoxTwo[4]=Twoy+10;
BoxTwo[5]=Twoz;
BoxTwo[6]=Twoz+10;

if((BoxOne[1] >= BoxTwo[1]) && (BoxOne[1] <= BoxTwo[2])){xcheck = 1;}
if((BoxOne[2] >= BoxTwo[1]) && (BoxOne[2] <= BoxTwo[2])){xcheck = true;}
if((BoxOne[3] >= BoxTwo[3]) && (BoxOne[3] <= BoxTwo[4])){ycheck = true;}
if((BoxOne[4] >= BoxTwo[3]) && (BoxOne[4] <= BoxTwo[4])){ycheck = true;}
if((BoxOne[5] >= BoxTwo[5]) && (BoxOne[5] <= BoxTwo[6])){zcheck = true;}
if((BoxOne[6] >= BoxTwo[5]) && (BoxOne[6] <= BoxTwo[6])){zcheck = true;}

if ((xcheck == true) && (ycheck == true)&& (zcheck == true)) {return true;}

else{return false;}

};
It is setup in my class like this:
bool CheckCollision(float FirstX,float FirstY,float FirstZ, float SecondX,float SecondY,float SecondZ);
And I'm calling it like this:
if(CheckCollision(scoutPos[1],scoutPos[2],scoutPos[3],entityPos[1],entityPos[2],entityPos[3])== true)
{
collide = true;
}
else{collide = false;}
I've asked a couple coders where they think the error might be occuring, but they're pretty stumped also. Would be great if one of you guys could figure it out :)

##### Share on other sites
Isnt it always the way that after searching everywhere and begging all comers for a solution you happen upon it yourself?

I needed
bool gGraphics::CheckCollision(float Onex,float Oney,float Onez, float Twox,float Twoy,float Twoz)

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631435
• Total Posts
3000056
×