Sign in to follow this  
ACiDuS

Error with collision function

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 this post


Link to post
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)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this