Add puck deceleration with drag and bounce reduction
Implemented ice friction physics for puck: - Added PUCK_DRAG (200 px/s²) to simulate ice friction - Reduced PUCK_BOUNCE from 1.0 to 0.6 for energy loss on collisions - Puck now naturally decelerates when loose instead of bouncing forever 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
a8daedf53b
commit
43ff271582
@ -46,6 +46,8 @@ export const PUCK_PICKUP_RADIUS = 1.5; // meters
|
|||||||
export const PUCK_CARRY_DISTANCE = 1.0; // meters in front of player
|
export const PUCK_CARRY_DISTANCE = 1.0; // meters in front of player
|
||||||
export const MAX_PUCK_VELOCITY = 50; // m/s
|
export const MAX_PUCK_VELOCITY = 50; // m/s
|
||||||
export const SHOT_SPEED = 30; // m/s
|
export const SHOT_SPEED = 30; // m/s
|
||||||
|
export const PUCK_DRAG = 200; // pixels/s² - ice friction (decelerates puck over time)
|
||||||
|
export const PUCK_BOUNCE = 0.6; // bounce coefficient (loses energy on wall/board collisions)
|
||||||
|
|
||||||
// Puck reception constants
|
// Puck reception constants
|
||||||
export const PUCK_RECEPTION_BASE_CHANCE = 0.8; // Base chance to receive puck (modified by handling skill)
|
export const PUCK_RECEPTION_BASE_CHANCE = 0.8; // Base chance to receive puck (modified by handling skill)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import Phaser from 'phaser';
|
import Phaser from 'phaser';
|
||||||
import { SCALE, MAX_PUCK_VELOCITY, PUCK_RADIUS } from '../config/constants';
|
import { SCALE, MAX_PUCK_VELOCITY, PUCK_RADIUS, PUCK_DRAG, PUCK_BOUNCE } from '../config/constants';
|
||||||
import { CoordinateUtils } from '../utils/coordinates';
|
import { CoordinateUtils } from '../utils/coordinates';
|
||||||
import type { PuckState, TeamSide, Position } from '../types/game';
|
import type { PuckState, TeamSide, Position } from '../types/game';
|
||||||
|
|
||||||
@ -44,8 +44,11 @@ export class Puck extends Phaser.GameObjects.Container {
|
|||||||
// Set initial velocity to 0 (stationary)
|
// Set initial velocity to 0 (stationary)
|
||||||
this.body.setVelocity(0, 0);
|
this.body.setVelocity(0, 0);
|
||||||
|
|
||||||
// Add bounce to keep it moving
|
// Add drag to simulate ice friction (puck decelerates over time)
|
||||||
this.body.setBounce(1, 1);
|
this.body.setDrag(PUCK_DRAG);
|
||||||
|
|
||||||
|
// Add bounce with energy loss on collisions
|
||||||
|
this.body.setBounce(PUCK_BOUNCE);
|
||||||
this.body.setCollideWorldBounds(true);
|
this.body.setCollideWorldBounds(true);
|
||||||
|
|
||||||
// Enable high-velocity collision detection
|
// Enable high-velocity collision detection
|
||||||
|
|||||||
@ -165,7 +165,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, 27, 5);
|
this.puck = new Puck(this, 5, 0);
|
||||||
|
|
||||||
// Add collisions between puck and all goal posts with custom bounce handler
|
// Add collisions between puck and all goal posts with custom bounce handler
|
||||||
this.physics.add.collider(this.puck, this.goalPostsGroup, this.handlePuckPostBounce, undefined, this);
|
this.physics.add.collider(this.puck, this.goalPostsGroup, this.handlePuckPostBounce, undefined, this);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user