# AABB-AABB collision response

**URL:** <https://forum.kirupa.com/t/aabb-aabb-collision-response/329089>\
**Category:** programming\
**Created:** [July 19, 2012, 1:29pm UTC](https://forum.kirupa.com/t/aabb-aabb-collision-response/329089 "2012-07-19T13:29:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rinalds\_Zukulis](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@Rinalds\_Zukulis](https://forum.kirupa.com/u/Rinalds_Zukulis)\
**Post date:** [July 19, 2012, 1:29pm UTC](https://forum.kirupa.com/t/aabb-aabb-collision-response/329089/1 "2012-07-19T13:29:36Z")

</div>

hey! so i have created AABB-AABB collision detection:

```auto

var lenX:Number = Math.abs(obj.x - (x+vx));                
var totalRadiusX:Number = obj.hx + hx;
var lenY:Number = Math.abs(obj.y - (y+vy));
var totalRadiusY:Number = obj.hy + hy;
                
if (totalRadiusX > lenX && totalRadiusY > lenY)
{
   var penX:Number = totalRadiusX - lenX;
   var dx:Number = utils.Sign(x + vx - obj.x);
                        
   var penY:Number = totalRadiusY - lenY;
   var dy:Number = utils.Sign(y+vy-obj.y);
                    
   if (Math.abs(penX) > Math.abs(penY))
   {
      y += vy + penY * dy;
      vy = 0;    
   }
   else if (Math.abs(penX) < Math.abs(penY))
   {
       x += vx + penX * dx;
       vx = 0;
   }
}

```

\*\*Metanet tut where 2 AABB collides have the same problem \*\*[http://www.metanetsoftware.com/technique/tutorialA.html#section1](http://www.metanetsoftware.com/technique/tutorialA.html#section1)

But the thing is it doesnt recognize corners.(because of test of which overlap is smaller but if there isn’t such code then it works even worse) **What should i do and is this even good method or is there better?** It would be cool if someone could provide me with some tutorials(  
except metanet because i am kinda working from their tuts).
