Gravity Shift Revolution: Mastering 3D Maze Rotation with Three.js and Cannon.js
This prompt was originally published by prompts.chat. It describes a puzzle-platformer named "Gravity Shift" where players rotate the entire world to navigate a 3D low-poly labyrinth. The environment uses minimalist design with pastel gradients and geometric shapes. You'll use AI tools like ChatGPT, Claude or Gemini to generate code based on this prompt. This tutorial guides you through building a working version locally before deploying it online for free.
We’ll walk through how to paste the prompt into an AI coding assistant, run the output, test gameplay features, and deploy your game without spending a cent. The core mechanics involve rotating gravity using Cannon.js and following the player with a smooth camera using Three.js interpolation.
What you need
- A computer with internet access
- An AI coding tool (ChatGPT, Claude, Gemini, Cursor, Bolt, Lovable, or v0)
- Text editor like VS Code or any code editor
- Basic understanding of JavaScript and HTML
- Web browser for testing locally
- Optional: GitHub account for deployment
The full prompt
Game Concept: A puzzle-platformer named "Gravity Shift" where players rotate the entire world to navigate a 3D low-poly labyrinth. The environment is minimalist, using pastel gradients and sharp geometric shapes.
Technical Prompt:
Build a 3D platformer using Three.js and Cannon.js. The world is a cube-shaped maze. When the user presses 'R', rotate the world.gravity vector by 90 degrees.
JavaScript
// Gravity rotation logic
world.gravity.set(0, -9.82, 0); // Default
function rotateGravity() {
let newG = new CANNON.Vec3(-world.gravity.y, world.gravity.x, 0);
world.gravity.copy(newG);
}
Include smooth camera interpolation using Lerp to follow the player's rigid body during shifts.1Paste the Full Prompt in an AI Coding Tool
Start by opening one of your preferred AI coding tools such as ChatGPT, Claude, or Gemini. Copy and paste the full prompt from this page into the input field. The prompt includes a clear technical specification for using Three.js and Cannon.js to build a 3D platformer with gravity rotation.
Make sure you are pasting exactly what is listed under "The full prompt" in this tutorial. Avoid adding extra text or modifying any part of the provided code. This ensures that the AI understands your intent correctly.
After pasting, let the AI generate the entire project structure and code. Once done, review the output carefully before proceeding to the next step.

Pro tip: Always use a clean copy of the prompt without any edits to avoid drift in AI generation.
2Save the Generated Code Locally
Once the AI finishes generating the code, save it as a single HTML file named index.html. This will be your main project file. It should include all necessary libraries like Three.js and Cannon.js.
The generated output may contain multiple files or a single HTML with embedded JavaScript. If needed, create separate folders for assets and scripts if the AI outputs more than one file.
You can also use Cursor or Bolt to scaffold the project directly from the prompt. These tools allow you to generate and edit code in real time, which speeds up development.
Pro tip: Use a local server (e.g., Live Server extension in VS Code) to test your game locally.
3Test the Basic Game Mechanics
Open index.html in your browser and verify that the basic mechanics work. Look for:
- A 3D scene with a rotating cube maze
- The player character (usually a sphere or capsule)
- Keyboard controls to rotate gravity using 'R'
- Physics interaction between the player and environment
The game should start with gravity pulling the player down, and pressing 'R' should rotate the world's gravity vector by 90 degrees. If this doesn't happen, check for errors in the console and ensure all libraries are loaded correctly.

Pro tip: Press F12 to open DevTools and look for JavaScript errors if things don’t load properly.
4Implement Smooth Camera Interpolation
One of the key parts from the prompt is smooth camera interpolation using Lerp. Ensure that the camera follows the player’s rigid body with a slight delay to avoid jittering.
If the camera jumps or feels unresponsive, adjust the lerp factor in your camera update loop. Typically, a value between 0.05 and 0.1 works well for smooth motion.
This feature improves gameplay feel by making movement more natural, especially during gravity shifts where the player might be moving quickly in new directions.
Pro tip: Try different lerp values to find a balance between responsiveness and smoothness.
5Fix Rotation Logic Bugs
If pressing 'R' doesn’t rotate gravity correctly, there might be an issue in how the world.gravity is updated. Double-check that the vector rotation logic matches the prompt exactly:
function rotateGravity() {
let newG = new CANNON.Vec3(-world.gravity.y, world.gravity.x, 0);
world.gravity.copy(newG);
}
Make sure this function is called properly on key press and that it updates the direction of gravity for all objects in the scene. Also verify that no other code overrides gravity after rotation.
Pro tip: Log world.gravity to the console before and after rotation to debug unexpected behavior.
6Test Physics and Collision Detection
Check if the player can walk on surfaces and interact with walls properly. If collisions are not working or the player falls through floors, ensure:
- Proper rigid body setup for both player and environment
- Correct use of Cannon.js
WorldandBodyclasses - That gravity is applied to all bodies correctly after rotation
Adjust collision shapes if needed. You can add debug visuals by enabling Three.js's built-in debug renderer for physics objects.
Ensure that the player’s movement feels responsive, especially when shifting between different gravity states.
Pro tip: Use cannon-es or cannon.js debug mode to visualize collision boundaries during testing.
7Optimize Rendering Performance
With a 3D scene and physics, performance matters. The AI may generate code that works but isn't optimized for real-time rendering.
Try these optimizations:
- Limit camera distance to reduce unnecessary rendering
- Use
requestAnimationFrameefficiently - Avoid recalculating matrices or vectors unnecessarily
- Consider reducing the number of dynamic objects if possible
Monitor FPS in DevTools. If it drops below 30, revisit your rendering and update loops.
Pro tip: Use browser performance tools to profile frames and identify bottlenecks.
8Add Visual Polish and HUD Elements
Enhance the minimalist look of the game by adding:
- Pastel gradient backgrounds or skyboxes
- Simple UI elements like a gravity direction indicator
- Instructions on screen to guide players
- Sound effects for gravity shifts (optional)
These small touches improve the feel and usability without overcomplicating the core mechanics. The visual style of the game should match the prompt’s low-poly aesthetic.
Ensure all visuals are lightweight and don’t affect performance.
Pro tip: Use CSS or Three.js materials to apply gradients and lighting effects without heavy shaders.
9Deploy for Free Using GitHub Pages
To share your game online, deploy it using GitHub Pages or Netlify. For GitHub:
- Create a new repository on GitHub
- Push your
index.htmland any assets to the repo - Enable GitHub Pages in Settings
- Visit the live URL to test
GitHub Pages provides a free CDN and handles hosting automatically. This allows anyone to play your game directly from the web.
Alternatively, use Netlify or Vercel for easy one-click deployments.
Pro tip: Ensure all asset paths are relative so your game works when deployed online.
10Iterate and Expand Game Features
Once the base is working, expand with:
- Multiple levels or mazes
- Collectible items or power-ups
- Sound effects and music
- Mobile touch controls for mobile play
- Pause menu and restart button
Each new feature can be added one at a time using follow-up prompts. For example, ask AI to add a timer or score system.
Keep the design simple to maintain performance and readability.
Pro tip: Ask the AI to generate code for each new feature separately to avoid overwhelming complexity.
11Share Your Game with Others
After completing your game, share it with friends or on social media. Consider uploading it to platforms like Itch.io or GitHub.
The prompt you used is flexible enough to inspire many variations, try changing the maze layout, adding color changes with gravity shifts, or implementing a story mode.
This tutorial shows how easy it is to build a complete 3D platformer using AI coding tools. You can now apply similar techniques to other game ideas and challenges.
Pro tip: Encourage others to copy the prompt from this page and experiment with their own versions.
Adapt it to your own brand
- Change the maze structure by modifying the geometry of walls or adding new shapes.
- Swap out pastel gradients for solid colors or textured backgrounds to change the visual theme.
- Add a scoring system or time trial mode to challenge players further.
- Implement mobile touch controls for playing on smartphones and tablets.
- Introduce sound effects or music that plays during gravity shifts for better immersion.
- Modify physics parameters such as friction or bounce for different gameplay feel.
- Use different camera angles (e.g., top-down view) instead of first-person perspective.
Common mistakes and fixes
- Forgetting to load Cannon.js and Three.js libraries properly can break the entire game. Always include them via CDN or local files.
- Not setting up gravity rotation correctly leads to incorrect movement physics after pressing 'R'. Double-check vector math logic.
- Improper camera interpolation causes janky visuals during world rotations. Use consistent lerp values.
- Incorrect collision shapes result in players falling through floors. Make sure all bodies have correct shape definitions.
- Adding too many dynamic elements can cause performance drops. Keep updates minimal.
- Forgetting to use relative paths when deploying breaks asset loading on live servers.
Frequently asked questions
Which AI tools work best for this prompt?
ChatGPT, Claude, Gemini, Cursor, Lovable, and Bolt all support this kind of project. They produce working code based on the detailed prompt.
Can I run this game locally?
Yes, save the output as an HTML file and open it in any modern browser. A local server helps with asset loading and debugging.
How do I deploy my game for free?
Use GitHub Pages or Netlify. Both offer free hosting for static websites like this one.
What are the core mechanics of Gravity Shift?
Players rotate gravity by pressing 'R' to change which direction they fall, navigating a 3D maze using physics and spatial reasoning.
Final thoughts
This tutorial shows how AI can be used to generate working games quickly. By pasting the prompt into tools like ChatGPT or Claude, you’ve built a functional 3D platformer with gravity rotation. You’ve tested core features, fixed bugs, and deployed it for free online. Now copy the prompt above and experiment with your own variations. Build new levels, add sound, or change visuals to make it uniquely yours.