From 7a403b57dadc10a81e98f5cf4b68a0128e100695 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Sat, 22 Feb 2025 10:25:42 +0800 Subject: chore: use predicted location to detect collision with obstacles --- objects/Obstacle.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'objects/Obstacle.lua') diff --git a/objects/Obstacle.lua b/objects/Obstacle.lua index abea419..fb66611 100644 --- a/objects/Obstacle.lua +++ b/objects/Obstacle.lua @@ -23,3 +23,12 @@ function Obstacle:getBorders() return { left, right, top, bottom } end + +function Obstacle:isMet(body, currentX, currentY, dv) + -- x,y should be the predicted next location of this body + -- dv = speed * dt * direction + local x = currentX + dv + local y = currentY + dv + + return self.body:collide(body, self.x, self.y, x, y) +end -- cgit v1.2.3