From 66c949e47d5e04fcb2aa0addbb81efb4d6319767 Mon Sep 17 00:00:00 2001 From: Pierre Wessman <4029607+pierrewessman@users.noreply.github.com> Date: Fri, 19 Sep 2025 13:19:01 +0200 Subject: [PATCH] Fix goalie collision on failed saves by adding 500ms cooldown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When goalies fail to save shots, they now have a 500ms collision cooldown to prevent the puck from bouncing off them repeatedly. This allows the puck to continue into the goal after a failed save. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/entities/puck.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/entities/puck.js b/src/entities/puck.js index 8cadc2a..afe04fa 100644 --- a/src/entities/puck.js +++ b/src/entities/puck.js @@ -12,6 +12,9 @@ class Puck { this.bounceCount = 0; this.trail = []; this.maxTrailLength = 10; + + // Collision cooldown tracking + this.goalieCollisionCooldowns = new Map(); // Maps player ID to cooldown end time } update(deltaTime, gameState, players) { @@ -91,6 +94,24 @@ class Puck { } } + isGoalieOnCooldown(goalie) { + const playerId = goalie.id || `${goalie.team}-${goalie.role}`; + const cooldownEnd = this.goalieCollisionCooldowns.get(playerId); + if (cooldownEnd && Date.now() < cooldownEnd) { + return true; + } + // Clean up expired cooldowns + if (cooldownEnd && Date.now() >= cooldownEnd) { + this.goalieCollisionCooldowns.delete(playerId); + } + return false; + } + + setGoalieCooldown(goalie, durationMs = 500) { + const playerId = goalie.id || `${goalie.team}-${goalie.role}`; + this.goalieCollisionCooldowns.set(playerId, Date.now() + durationMs); + } + checkBoardCollisions(gameState) { const rink = gameState.rink; let collision = false; @@ -302,6 +323,11 @@ class Puck { let closestDistance = Infinity; players.forEach(player => { + // Skip goalies who are on collision cooldown + if (player.role === 'G' && this.isGoalieOnCooldown(player)) { + return; + } + const distance = this.position.distance(player.position); const collisionDistance = this.radius + player.radius; @@ -392,10 +418,13 @@ class Puck { difficulty: difficulty }); } else { - console.log("Failed save") + console.log("Failed save - setting collision cooldown") // Failed save - puck continues with reduced velocity (already bounced from collision) // The collision physics have already been applied, so the puck will continue toward the goal this.velocity = this.velocity.multiply(0.8); // Slightly reduce speed but let it continue + + // Set collision cooldown to prevent immediate re-collision with goalie + this.setGoalieCooldown(goalie, 500); // 500ms cooldown } } @@ -417,6 +446,9 @@ class Puck { this.lastTeamTouch = null; this.bounceCount = 0; this.trail = []; + + // Clear all goalie collision cooldowns + this.goalieCollisionCooldowns.clear(); } faceoffDrop(winningTeam, location, participants) {