Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function resolveCollisionX(a, b, dX, dY) {
- var sum = createAABB(b.x, b.y, b.width + a.width, b.height + a.height);
- var time = 1;
- if (dX > 0) {
- if (a.x + dX > sum.x - sum.halfWidth) {
- time = ((sum.x - sum.halfWidth) - a.x) / dX;
- if (a.y + dY * time > sum.y - sum.halfHeight && a.y + dY * time < sum.y + sum.halfHeight && time >= 0) {
- return time;
- }
- }
- } else if (dX < 0) {
- if (a.x + dX < sum.x + sum.halfWidth) {
- time = ((sum.x + sum.halfWidth) - a.x) / dX;
- if (a.y + dY * time > sum.y - sum.halfHeight && a.y + dY * time < sum.y + sum.halfHeight && time >= 0) {
- return time;
- }
- }
- }
- return 1;
- }
- function resolveCollisionY(a, b, dX, dY) {
- var sum = createAABB(b.x, b.y, b.width + a.width, b.height + a.height);
- var time = 1;
- if (dY > 0) {
- if (a.y + dY > sum.y - sum.halfHeight) {
- time = ((sum.y - sum.halfHeight) - a.y) / dY;
- if (a.x + dX * time > sum.x - sum.halfWidth && a.x + dX * time < sum.x + sum.halfWidth && time >= 0) {
- return time;
- }
- }
- } else if (dY < 0) {
- if (a.y + dY < sum.y + sum.halfHeight) {
- time = ((sum.y + sum.halfHeight) - a.y) / dY;
- if (a.x + dX * time > sum.x - sum.halfWidth && a.x + dX * time < sum.x + sum.halfWidth && time >= 0) {
- return time;
- }
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement