Planet gravity
World gravity is switched off; instead the character carries a radial gravity
field pointing at the planet’s center. With useCharacterUpAxis, auto-balance
keeps it standing upright relative to the surface, so it walks a great circle
right around the little world.
Drag to orbit
How it works
Section titled “How it works”import { Vector3 } from "three";
const gravity = new Vector3();const controller = new CharacterController({ world, // created with gravity [0, 0, 0] position: [0, R + 0.9, 0], enableCustomGravity: true, useCharacterUpAxis: true, // control relative to the body's own up gravityField: (p) => gravity.copy(p).normalize().multiplyScalar(-9.81),});
function fixedStep(dt) { controller.setForwardDirection(controller.bodyZAxis); // walk along current facing controller.setMovement({ forward: true }); controller.step(dt); world.step(dt);}See also
Section titled “See also”- Custom Gravity — gravity fields, the up-axis, and wall/planet walking.