Skip to content

Commit

Permalink
Fix Aabb/Circle collision check
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Nov 21, 2023
1 parent 7e1f93b commit 49e6e75
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vole-engine/core",
"version": "0.0.26",
"version": "0.0.27",
"description": "Tiny 2D game engine",
"repository": "https://github.com/dinomintstudio/vole",
"author": "ivanjermakov",
Expand Down
4 changes: 2 additions & 2 deletions src/collision/aabb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export class Aabb implements Collider {
// https://gamedev.stackexchange.com/a/178154
const dist = other.center.sub(this.center)
const clamped = vec(
clamp(dist.x, this.center.x - this.size.x, this.center.x + this.size.x),
clamp(dist.y, this.center.y - this.size.y, this.center.y + this.size.y),
clamp(dist.x, -this.size.x * 0.5, this.size.x * 0.5),
clamp(dist.y, -this.size.y * 0.5, this.size.y * 0.5),
)
const closest = this.center.add(clamped)
return closest.distance(other.center) <= other.radius
Expand Down

0 comments on commit 49e6e75

Please sign in to comment.