Add player collision with goal posts to prevent skating through goals
- Add physics colliders between all players and goal post structures - Players now collide with left/right posts and back bars of both goals - Prevents unrealistic behavior of skating through goal frames 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2e2f065838
commit
db16ec2a04
@ -115,7 +115,7 @@ export class GameScene extends Phaser.Scene {
|
|||||||
|
|
||||||
private createPuck() {
|
private createPuck() {
|
||||||
// Initialize puck at center ice (0, 0 in game coordinates)
|
// Initialize puck at center ice (0, 0 in game coordinates)
|
||||||
this.puck = new Puck(this, 20, 5);
|
this.puck = new Puck(this, 27, 5);
|
||||||
|
|
||||||
// Add collisions between puck and goal posts with custom bounce handler
|
// Add collisions between puck and goal posts with custom bounce handler
|
||||||
this.physics.add.collider(this.puck, this.leftGoal.getLeftPost(), this.handlePuckPostBounce, undefined, this);
|
this.physics.add.collider(this.puck, this.leftGoal.getLeftPost(), this.handlePuckPostBounce, undefined, this);
|
||||||
@ -124,6 +124,16 @@ export class GameScene extends Phaser.Scene {
|
|||||||
this.physics.add.collider(this.puck, this.rightGoal.getLeftPost(), this.handlePuckPostBounce, undefined, this);
|
this.physics.add.collider(this.puck, this.rightGoal.getLeftPost(), this.handlePuckPostBounce, undefined, this);
|
||||||
this.physics.add.collider(this.puck, this.rightGoal.getRightPost(), this.handlePuckPostBounce, undefined, this);
|
this.physics.add.collider(this.puck, this.rightGoal.getRightPost(), this.handlePuckPostBounce, undefined, this);
|
||||||
this.physics.add.collider(this.puck, this.rightGoal.getBackBar(), this.handlePuckPostBounce, undefined, this);
|
this.physics.add.collider(this.puck, this.rightGoal.getBackBar(), this.handlePuckPostBounce, undefined, this);
|
||||||
|
|
||||||
|
// Add player collisions with goal posts (prevent skating through goals)
|
||||||
|
this.players.forEach(player => {
|
||||||
|
this.physics.add.collider(player, this.leftGoal.getLeftPost());
|
||||||
|
this.physics.add.collider(player, this.leftGoal.getRightPost());
|
||||||
|
this.physics.add.collider(player, this.leftGoal.getBackBar());
|
||||||
|
this.physics.add.collider(player, this.rightGoal.getLeftPost());
|
||||||
|
this.physics.add.collider(player, this.rightGoal.getRightPost());
|
||||||
|
this.physics.add.collider(player, this.rightGoal.getBackBar());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private createGoals() {
|
private createGoals() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user