I've been following this pseudo code for my implementation of 2D AABB Swept Collision:
if moving.vel.x < 0 then distX = static.right - moving.left else distX = static.left - moving.right endif if moving.vel.y < 0 then distY = static.bottom - moving.top else distY = static.top - moving.bottom endif timeX = distX / moving.vel.x timeY = distY / moving.vel.y collisionTime = min(timeX, timeY) moving.move(collisionTime * moving.vel.x, collisionTime * moving.vel.y)
In this image/example, the red box is the moving object (traveling from the bottom left corner to the to right corner), while the black box is the wall. There is suppose to be no collisions along the way.
The first issue here is I need to ignore the timeX (pseudo code above) calculated as the red box and the black box already overlaps with each other on the x axis before the movement began. I have already implemented this feature.
The problem now is following this algorithm while traveling up-right, we would use the black box's bottom y coordinate - the red box's top y coordinate to calculate the distance between the two. If the distance of this result is less than the red box's y-velocity then timeY will yield a number that is less than 1.0f. This indicates there is a collision, which is wrong in the cases where the x velocity is high enough, meaning the red box should be traveling unhindered no matter how fast its velocity is in this case. FYI, I have broadphasing implemented, and this black box is included as a list of possible collision candidates. I assume I have to check the X velocity? But I already decided to ignore the x-velocity in the problem above. Is there anything I can do to fix this case? Or do I have to do something that is completely different? E.g. Minkowski?
Thanks for the help. I really appreciate it. Sincerely, errandel