Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualxinfinite33

Posted 26 December 2012 - 11:13 AM

the way i would do it is to just do a bounding box collision check, then if there was a collision i would correct on the axis with the lowest penetration value. the penetration value is how far one bounding box has penetrated another . so you get the penetration value of both the x axis and the y axis. and correct for the smallest penetration value. you can get the penetration value by taking the distance from the center of the bounding box to the edge of the bounding box "width/2 or height /2". for both bounding boxes, and then subtract it from the distance from the center of box 1 to  the center of box 2:

 


int Xpenetration=( ( Boundingbox1.width/2 + Boundingbox2.width/2 ) - (Boundingbox2.centerX-Boundingbox1.centerX) );

int Ypenetration=( ( Boundingbox1.height/2 + Boundingbox2.height/2 ) - (Boundingbox2.centerY-Boundingbox1.centerY) );

 

 

then you compare the absolute value of both the Xpenetration and the Ypenetration, and just correct for the smallest value:

 

if( abs(Xpenetration) > abs(Ypenetration) )
{
   // correct on the y axis using Ypenetration value.
}
else 
{
   // correct on the x axis using Xpenetration value.
} 

#1xinfinite33

Posted 26 December 2012 - 11:12 AM

the way i would do it is to just do a bounding box collision check, then if there was a collision i would return the lowest penetration value of the two axis's. the penetration value is how far one bounding box has penetrated another . so you get the penetration value of both the x axis and the y axis. and correct for the smallest penetration value. you can get the penetration value by taking the distance from the center of the bounding box to the edge of the bounding box "width/2 or height /2". for both bounding boxes, and then subtract it from the distance from the center of box 1 to  the center of box 2:

 


int Xpenetration=( ( Boundingbox1.width/2 + Boundingbox2.width/2 ) - (Boundingbox2.centerX-Boundingbox1.centerX) );

int Ypenetration=( ( Boundingbox1.height/2 + Boundingbox2.height/2 ) - (Boundingbox2.centerY-Boundingbox1.centerY) );

 

 

then you compare the absolute value of both the Xpenetration and the Ypenetration, and just correct for the smallest value:

 

if( abs(Xpenetration) > abs(Ypenetration) )
{
   // correct on the y axis using Ypenetration value.
}
else 
{
   // correct on the x axis using Xpenetration value.
} 

PARTNERS