T = PlayerAABB.position - PlatformAABB.position
T = PlayerAABB.position - PlatformAABB.position
Tx = player.x - platform.x
Ty = player.y - platform.y
Tx = player.x - platform.x
Ty = player.y - platform.y
Tx = (player.left + player.width / 2) - (platform.left + platform.width / 2)
Ty = (player.top + player.height / 2) - (platform.top + platform.height / 2)
Tx = (player.left + player.width / 2) - (platform.left + platform.width / 2)
Ty = (player.top + player.height / 2) - (platform.top + platform.height / 2)
To detect if boxes overlap
if (absolute(T.x) > (currentSpr.width / 2) + (otherSpr.width / 2)) stop here;
if (absolute(T.y) > (currentSpr.height / 2) + (otherSpr.height / 2)) stop here;
if (absolute(T.x) > (currentSpr.width / 2) + (otherSpr.width / 2)) stop here;
if (absolute(T.y) > (currentSpr.height / 2) + (otherSpr.height / 2)) stop here;
penx = (currentSpr.width / 2) + (otherSpr.width / 2) - absolute(T.x);
peny = (currentSpr.height / 2) + (otherSpr.height / 2) - absolute(T.y);
penx = (currentSpr.width / 2) + (otherSpr.width / 2) - absolute(T.x);
peny = (currentSpr.height / 2) + (otherSpr.height / 2) - absolute(T.y);
if (penx < peny) currentSpr.left -= penx * (T.x >= 0 ? 1 : -1) / 2;
else currentSpr.top -= peny * (T.y >= 0 ? 1 : -1) / 2;
if (penx < peny) currentSpr.left -= penx * (T.x >= 0 ? 1 : -1) / 2;
else currentSpr.top -= peny * (T.y >= 0 ? 1 : -1) / 2;