Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
refactor: small collision fn stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Sep 14, 2024
1 parent 0f1f1bc commit 5e63447
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
12 changes: 2 additions & 10 deletions shared/utils/coldet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,7 @@ export const coldet = {
return null;
},

intersectAabbCircle(
min: Vec2,
max: Vec2,
pos: Vec2,
rad: number,
_isPlayerCollision = false,
) {
intersectAabbCircle(min: Vec2, max: Vec2, pos: Vec2, rad: number) {
if (pos.x >= min.x && pos.x <= max.x && pos.y >= min.y && pos.y <= max.y) {
const e = v2.mul(v2.sub(max, min), 0.5);
const c = v2.add(min, e);
Expand All @@ -359,9 +353,7 @@ export const coldet = {
math.clamp(pos.x, min.x, max.x),
math.clamp(pos.y, min.y, max.y),
);
let dir = v2.sub(pos, cpt);

dir = v2.sub(pos, cpt);
const dir = v2.sub(pos, cpt);

const dstSqr = v2.lengthSqr(dir);
if (dstSqr < rad * rad) {
Expand Down
3 changes: 1 addition & 2 deletions shared/utils/collider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const collider = {

return pts;
},
// @TODO: Ensure consistent pen dirs (ie towards 2nd arg)

intersectCircle(col: Collider, pos: Vec2, rad: number) {
if (col.type === collider.Type.Aabb) {
return coldet.intersectAabbCircle(col.min, col.max, pos, rad);
Expand All @@ -117,7 +117,6 @@ export const collider = {
if (col.type === collider.Type.Aabb) {
return coldet.intersectAabbAabb(col.min, col.max, min, max);
}
// @TODO: pen dir is reversed
return coldet.intersectAabbCircle(min, max, col.pos, col.rad);
},

Expand Down

0 comments on commit 5e63447

Please sign in to comment.