Skip to content

feat: implement keyboard-driven car simulation game#11

Open
novo3d-open-swe[bot] wants to merge 17 commits into
mainfrom
open-swe/52ee9116-7644-42ea-a96a-2190928049a3
Open

feat: implement keyboard-driven car simulation game#11
novo3d-open-swe[bot] wants to merge 17 commits into
mainfrom
open-swe/52ee9116-7644-42ea-a96a-2190928049a3

Conversation

@novo3d-open-swe

@novo3d-open-swe novo3d-open-swe Bot commented Jan 15, 2026

Copy link
Copy Markdown

Fixes #10

Overview

This pull request implements a complete keyboard-driven car simulation game using Three.js. The game features a drivable car with realistic physics, a detailed game environment, and a third-person follow camera.

Key Features

Car System

  • Car Class (src/Main/Car.js): Fully functional vehicle with:
    • 3D model built from Three.js primitives (body, roof, windows, wheels)
    • Realistic physics simulation (velocity, acceleration, friction, steering)
    • Speed-based turning mechanics
    • Handbrake functionality with increased friction
    • Real-time speed display in HUD
    • Shadow casting for visual depth

Game Environment

  • Environment Class (src/Main/Environment.js): Complete game world with:
    • Large 200x200 ground plane with grid texture
    • Sky dome with atmospheric fog
    • Boundary walls around the play area
    • Scattered obstacles (traffic cones, boxes, pillars)
    • Proper shadow receiving for all surfaces

Input System

  • KeyboardControls Class (src/Main/KeyboardControls.js): Responsive keyboard input handling:
    • W/Arrow Up: Accelerate
    • S/Arrow Down: Brake/Reverse
    • A/Arrow Left: Turn left
    • D/Arrow Right: Turn right
    • Space: Handbrake

Camera System

  • Third-person follow camera with smooth lerp interpolation
  • Maintains fixed offset behind and above the car
  • Looks ahead of the car for better visibility
  • Automatically rotates with the car

User Interface

  • Speed Display: Real-time speed indicator in km/h
  • Controls Info: On-screen keyboard control instructions
  • HUD Styling: Semi-transparent backgrounds with high contrast for readability

Technical Changes

Modified Files

  • src/Main/Main.js: Wired up all components, removed OrbitControls
  • src/Main/Geometry.js: Replaced red cube with Car and Environment instances
  • src/Main/Camera.js: Implemented third-person follow camera with smooth interpolation
  • src/Main/Controls.js: Replaced OrbitControls with KeyboardControls
  • src/Main/Animate.js: Added car physics and camera updates to animation loop
  • src/Main/Utils/Helpers.js: Removed debug helpers (AxesHelper, GridHelper)
  • src/style.css: Added HUD styling, removed unused .label class
  • src/index.html: Added HUD elements for speed display and controls

New Files

  • src/Main/Car.js: Complete car simulation with physics
  • src/Main/Environment.js: Game world generation
  • src/Main/KeyboardControls.js: Keyboard input management

Physics Implementation

  • Frame-rate independent physics using deltaTime
  • Velocity-based movement with forward direction calculated from car rotation
  • Friction system that naturally slows the car
  • Handbrake applies 3x friction for dramatic stopping
  • Speed clamping to prevent unrealistic velocities
  • Steering that only works when the car is moving

Visual Enhancements

  • Shadow casting enabled on all car parts
  • Atmospheric fog for depth perception
  • Grid helper on ground plane for spatial reference
  • Semi-transparent HUD elements for readability over 3D scene

Note

Builds a playable car demo with physics, input, camera follow, and on-screen HUD.

  • Add Car (physics: acceleration/brake/friction/turning, wheel rotation) and speed HUD updates
  • Add Environment (200x200 ground with grid, sky/fog, boundary walls, cones/boxes/pillars)
  • Add KeyboardControls and switch Controls to use it (replaces OrbitControls)
  • Update Camera to third-person follower with update (offset, look-ahead, lerp); render via camera.camera
  • Update Animate loop to call car.update(...) and camera.update(...)
  • Update Geometry to instantiate Environment and Car; simplify Helpers
  • Add HUD elements in index.html and styling in style.css
  • Fix resize to use camera.camera

Written by Cursor Bugbot for commit 2a93b31. This will update automatically on new commits. Configure here.

@coderabbitai

coderabbitai Bot commented Jan 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


Comment @coderabbitai help to get the list of available commands and usage tips.

@novo3d-open-swe novo3d-open-swe Bot changed the title [WIP]: Create a car simulation game using Three.js feat: implement keyboard-driven car simulation game Jan 15, 2026
@Morgadoo Morgadoo marked this pull request as ready for review January 15, 2026 03:31

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Comment thread src/Main/Camera.js
Comment thread src/Main/Car.js
const wheelRotation = speed * deltaTime * 2
this.wheels.forEach(wheel => {
wheel.rotation.x += wheelRotation
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wheel rotation ignores reverse movement direction

Medium Severity

The wheel rotation calculation uses speed (velocity magnitude), which is always positive. When the car reverses, wheels visually spin forward instead of backward. The rotation direction needs to account for whether the car is moving forward or backward relative to its facing direction, but currently wheelRotation is always added regardless of movement direction.

Fix in Cursor Fix in Web

Comment thread src/Main/Car.js
// Clamp to max speed
if (speed > this.maxSpeed) {
this.velocity.normalize().multiplyScalar(this.maxSpeed)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale speed value used after friction modifies velocity

Low Severity

The speed variable is calculated at line 133 before friction is applied, but then used at lines 141, 146, and 148 after friction has modified this.velocity. The max speed clamping check and turn calculations use stale pre-friction values. This can cause the max speed clamp to override friction effects, making the car slightly faster than it should be after friction is applied.

Additional Locations (1)

Fix in Cursor Fix in Web

- Remove incorrect return statement from Camera constructor that was
  returning the raw THREE.PerspectiveCamera instead of the wrapper class
- Update Animate.js and Main.js to access camera.camera for rendering
- Swap left/right turn direction values in KeyboardControls to fix
  inverted steering
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create a car simulation game using Three.js

1 participant