@web-engine-dev/character
Character movement controllers for web-engine-dev. Supports platformer, first-person, third-person, and top-down movement styles.
Features
- Platformer Controller: Jump, wall-jump, ground detection
- First-Person Controller: Mouse look, strafe movement
- Third-Person Controller: Camera-relative movement, orbiting
- Top-Down Controller: WASD or click-to-move styles
- Kinematic Movement: Non-physics based movement
- Ground/Wall Detection: Surface detection raycasts
Installation
bash
npm install @web-engine-dev/character
# or
pnpm add @web-engine-dev/characterQuick Start
typescript
import {
CharacterController,
PlatformerController,
FirstPersonController,
} from '@web-engine-dev/character';
// Platformer-style controller
const player = new PlatformerController({
moveSpeed: 8,
jumpForce: 15,
gravity: 30,
groundCheckDistance: 0.1,
});
// Update each frame
player.update(deltaTime, input);
const movement = player.getVelocity();Controller Types
Platformer Controller
typescript
const controller = new PlatformerController({
moveSpeed: 8,
jumpForce: 15,
gravity: 30,
maxJumps: 2, // Double jump
coyoteTime: 0.1, // Jump grace period
jumpBuffer: 0.1, // Input buffering
wallSlideSpeed: 2,
wallJumpForce: 12,
});
controller.setInput({
horizontal: inputX, // -1 to 1
jump: jumpPressed,
});First-Person Controller
typescript
const controller = new FirstPersonController({
moveSpeed: 5,
sprintSpeed: 8,
mouseSensitivity: 0.002,
verticalLookLimit: 85,
});
controller.processMouseDelta(dx, dy);
controller.setMoveInput(forward, strafe);Third-Person Controller
typescript
const controller = new ThirdPersonController({
moveSpeed: 5,
rotationSpeed: 10,
cameraFollowSpeed: 5,
cameraDistance: 5,
});
controller.setCameraTarget(playerPosition);
controller.setMoveInput(inputDir);Top-Down Controller
typescript
const controller = new TopDownController({
moveSpeed: 6,
rotateTowardsMouse: true,
});
controller.setMoveInput(inputDirection);
controller.setLookTarget(mouseWorldPosition);Peer Dependencies
@web-engine-dev/math- Vector/quaternion math