title: Swept-AABB vs AABB Collision Test Not Working
body: <p>I'm trying to port Gomez's Swept-AABB vs AABB collision detection algorithm as shown <a href="http://www.gamasutra.com/view/feature/131790/simple_intersection_tests_for_games.php?page=3" rel="nofollow">on this page</a> to Lua, and I can't get it to work. It will detect "collisions" with the output time equal to zero pretty much everywhere, among other inaccuracies.  Am I doing something wrong?</p>
  
  <pre><code>local axis = {"x","y","z"}
  -- box1 is the moving box, disp is the box's displacement, box2 is stationary
  function Collision.swept_aabb_vs_aabb(box1, disp, box2)
      local a = box2
      local b = box1
      local amin = a:minCorner()
      local amax = a:maxCorner()
      local bmin = b:minCorner()
      local bmax = b:maxCorner()
      local u0d, u1d = vector(0,0,0), vector(1,1,1)
  
      for i=1,3 do
          local ax = axis[i]
          if amax[ax] &lt; bmin[ax] and disp[ax] &lt; 0 then
              u0d[ax] = (amax[ax] - bmin[ax]) / disp[ax]
          elseif bmax[ax] &lt; amin[ax] and disp[ax] &gt; 0 then
              u0d[ax] = (amin[ax] - bmax[ax]) / disp[ax]
          end
  
          if bmax[ax] &gt; amin[ax] and disp[ax] &lt; 0 then
              u1d[ax] = (amin[ax] - bmax[ax]) / disp[ax]
          elseif amax[ax] &gt; bmin[ax] and disp[ax] &gt; 0 then
              u1d[ax] = (amax[ax] - bmin[ax]) / disp[ax]
          end
      end
  
      local u0 = max(u0d.x,u0d.y,u0d.z)
      local u1 = min(u1d.x,u1d.y,u1d.z)
      if u0 &lt;= u1 then return u0 else return nil end
  end
  </code></pre>
  
  <p>EDIT: It seems that for all 3 axis that none of the if conditions that assign a value to u0d are triggered, will do some more testing.</p>