1. Constants and Configuration
- Player dimensions: HEIGHT (1.8), WIDTH (0.6)
- Movement speeds: WALK, SPRINT, SNEAK, FLY
- Physics constants: JUMP_SPEED, GRAVITY, TERMINAL_VELOCITY
- MOUSE_LOOK_SENSITIVITY for camera control
2. Player State Variables
- Position-related: isJumping, yVelocity, isOnGround
- Movement modes: isFlying, isSprinting, isSneaking
- Camera control: isPointerLocked, yaw, pitch
3. Vector and Object Reuse
- Predefine reusable vectors and objects to minimize garbage collection:
- moveVector, newPosition, slideVector, slidePosition
- collisionNormal, groundCheck
- playerBox, blockBox, blockPosition, matrix
4. Player Creation
- Function:
createPlayer(scene)
- Creates a box geometry representing the player
- Sets initial position, shadow properties
- Adds player to the scene
5. Player Controls
- Function:
addPlayerControls(player, camera, scene, canvas)
- Implements key mapping for movement and actions
- Handles mouse movement for camera rotation