An interactive 3D playground built to demonstrate a physics based character controller in the browser. This project combines the power of react-three-fiber for rendering, rapier for rigid body physics, and the excellent ecctrl library to handle complex character movements for both keyboard and gamepad.
This project serves as a boilerplate and learning resource for anyone looking to create third person 3D experiences on the web. The main goal was to integrate a robust character controller (ecctrl) with a dynamic physics world (@react-three/rapier). The scene includes basic objects to interact with and showcases how to implement smooth camera and player controls.
- Character Movement: Full player controls including walking and jumping.
- Dual Input Support: Seamlessly works with both Keyboard/Mouse and Gamepad/Joystick.
- Physics-Based World: Built with Rapier physics, allowing for realistic interactions like collisions, gravity, and object dynamics.
- Camera Controls: Uses
dreifor easy camera manipulation around the player. - Simple 3D Scene: A clean environment with platforms and obstacles to test movement and physics.
- React: UI library for building the application structure.
- React Three Fiber: A React renderer for Three.js, allowing for a declarative and component-based 3D scene.
- Drei: A collection of useful helpers and abstractions for React Three Fiber.
- Rapier: A fast and lightweight physics engine, used via the
@react-three/rapierlibrary. - Ecctrl: A flexible and easy-to-use character controller for React Three Fiber.
- Three.js: The underlying WebGL library that powers the 3D rendering.
To get a local copy up and running, follow these simple steps.
Make sure you have Node.js and npm (or yarn/pnpm) installed on your machine.
- Node.js (v16 or higher)
- npm
- Clone the repository:
git clone https://github.com/ayushh2k/r3f-playground
- Navigate to the project directory:
cd r3f-playground - Install the dependencies:
pnpm install
- Start the development server:
Your project should now be running on
pnpm run dev
http://localhost:5173
- Keyboard:
W, A, S, D: Move the character.Shift: Run.Space: Jump.
- Mouse:
Click and Drag: Rotate the camera around the player.
- Gamepad/Joystick:
Left Stick: Move the character.Bottom Face Button(e.g., A on Xbox controller): Jump.