Fix goalie collision on failed saves by adding 500ms cooldown
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 <noreply@anthropic.com>
This commit is contained in:
parent
15c24608d4
commit
66c949e47d
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user