scene
object
The three.js Scene object that holds every 3D mesh, light, and object in the game world.
let scene, camera, renderer, car, controls;
camera
object
The three.js PerspectiveCamera representing the player's viewpoint; repositioned every frame to follow either the car or the on-foot player.
let scene, camera, renderer, car, controls;
renderer
object
The THREE.WebGLRenderer that draws the scene from the camera's perspective into an HTML canvas each frame.
let scene, camera, renderer, car, controls;
car
object
A THREE.Group containing the car's body, cabin, and four wheels, moved and rotated together as one unit while driving.
let scene, camera, renderer, car, controls;
keys
object
A dictionary tracking which keyboard keys are currently held down (true/false), read every frame in animate() to drive movement.
let keys = {};
carSpeed
number
The car's current forward/backward speed, increased by acceleration input and decayed by deceleration/braking each frame.
let carSpeed = 0;
carAcceleration
number
How much carSpeed increases per frame while the accelerate key is held.
const carAcceleration = 0.05;
carDeceleration
number
How much carSpeed naturally decays per frame when no input is given, simulating friction/drag.
const carDeceleration = 0.02;
carMaxSpeed
number
The upper limit carSpeed is clamped to, capping how fast the car can drive.
const carMaxSpeed = 5;
carTurnSpeed
number
How many radians per frame the car rotates when turning left/right.
const carTurnSpeed = 0.03;
carBrakeDeceleration
number
How sharply carSpeed decreases per frame when the brake key is held, used instead of the slower natural deceleration.
const carBrakeDeceleration = 0.1;
player
object
A THREE.Group representing the on-foot character's body and position/rotation, used as the anchor for the first-person camera.
let player;
gun
object
The gun mesh attached directly to the camera so it renders in a fixed first-person position and can be hidden/shown by mode.
let gun;
npcs
array
Holds every NPC mesh currently in the scene; the shoot() function raycasts against this array and removes entries when NPCs are hit.
let npcs = [];
playerState
string
The core state machine flag, either 'driving' or 'onFoot', controlling which control scheme and camera behavior animate() runs.
let playerState = 'driving';
playerSpeed
number
How fast the on-foot player moves forward/backward per frame while walking.
const playerSpeed = 0.5;
playerTurnSpeed
number
How many radians per frame the player's view rotates when turning left/right on foot.
const playerTurnSpeed = 0.05;
shootingCooldown
number
Minimum milliseconds required between shots, preventing the gun from firing faster than this rate.
const shootingCooldown = 300; // milliseconds
lastShotTime
number
Timestamp (in milliseconds) of the last shot fired, compared against shootingCooldown to enforce fire-rate limiting.
let lastShotTime = 0;
raycaster
object
A reusable THREE.Raycaster instance used to cast a ray from the camera through the crosshair to detect which NPC was shot.
const raycaster = new THREE.Raycaster();
mouse
object
A THREE.Vector2 holding normalized screen coordinates for raycasting; fixed at (0,0), the exact center of the screen, since shots always fire from the crosshair.
const mouse = new THREE.Vector2();
gunshotSound
object
A p5.Oscillator used as a synthetic gunshot sound effect, triggered via quick amplitude ramps in shoot().
let gunshotSound;
crosshairElement
object
Reference to the HTML crosshair div, shown while on foot and hidden while driving.
let crosshairElement;