I've been learning collision detection recently and I already have understanding on how to detect collision. However for making solid objects, I'd have to push out the other object. I can't seem to figure out how to detect the approperiate direction to push the object out. I'm making a game for an older system, so the detection method should be fast. Some known values are the location of objects and the distance between them, how much the hitboxes overlap and movement speed. These values are separately as X and Y components, since vector calculation is too slow. All hitboxes are rectangles or points. Hitboxes themselves are simplified as a distance in X and Y axis that the distance between the objects has to be less than to have collision. I'd have to use that information to figure out which side of the hitbox the object is colliding and also detect when objects hit a corner exactly to treat as a special case to favor either X or Y pushout. Any ideas on how to do this?
How to detect the approperiate pushout direction for collision?
ok so effectively you're talking about adding an Impulse/Contact Solver to your physics world, which this high performing c++ lib can do for you in no time: https://box2d.org/documentation/md__d_1__git_hub_box2d_docs_collision.html#autotoc_md44
if u can't use it (or don't want to -lol-), and u still want to craft your physics from scratch then read about the kinetics here:
https://www.toptal.com/game/video-game-physics-part-i-an-introduction-to-rigid-body-dynamics
Part 2 & 3 are what u want but there's no harm in spending 36min to read all 3 parts;
have fun ?
I think the OP is asking a simpler question: how to resolve a collision between two AABBs.
This article hopefully gives some clues: https://blog.hamaluik.ca/posts/simple-aabb-collision-using-minkowski-difference/
The basic idea is: shrink one AABB to a point, and inflate the other by the same amount. Now you have to solve the penetration depth of a point vs an AABB (ie to find the vector that pushes the point to the surface of the AABB). Googling “AABB penetration vector” should be helpful – for some reason (perhaps this stupid ad-heavy garbage site redesign) I'm not able to post more links.. ?!