1.6 KiB
1.6 KiB
Design: Physics & Puck Dynamics (M2)
Goal
Implement basic physical properties for the puck to make movement feel natural: gradual slowing down (friction) and energy loss upon hitting boundaries (restitution).
Architecture
The physics logic will be integrated into the World.Update loop. Constants for physical properties will be defined to allow easy tuning of the game feel.
Implementation Details
1. Physical Constants
The following constants will be introduced:
PuckFriction: Multiplier applied to velocity every frame (e.g.,0.99).PuckRestitution: Multiplier applied to velocity upon boundary collision (e.g.,0.8).StopThreshold: Minimum velocity magnitude below which the puck is forced to a complete stop (e.g.,0.1).
2. Movement Logic (World.Update)
The update loop for the puck will follow these steps:
- Apply Friction:
velocity = velocity * PuckFriction. - Stop Check: If
length(velocity) < StopThreshold, thenvelocity = (0, 0). - Position Update:
position = position + velocity. - Boundary Collision:
- If the puck hits a boundary (considering its radius):
- Invert the velocity component perpendicular to the boundary.
- Multiply the resulting velocity by
PuckRestitution. - Correction: Snap the puck's position to be exactly on the boundary edge to prevent it from getting stuck inside the wall.
- If the puck hits a boundary (considering its radius):
Success Criteria
- The puck gradually slows down and eventually stops.
- The puck loses speed after bouncing off the walls.
- The puck does not get stuck in the boundaries.