This is a good fit for characters that need controlled blocking, sliding, and predictable steering.
When to Use It
Use CharacterController for:
- player characters
- endless runner characters
- enemies with scripted movement
- objects that should move deliberately rather than fall or roll freely
Use Rigidbody3D instead when physics should own the motion.
Scene Setup
In the editor:
- Select the character GameObject.
- Add a visible renderer or model.
- Add a collider shape that matches the gameplay body.
- Add
CharacterController. - Add your movement Behaviour.
Do not also make the same GameObject a dynamic Rigidbody3D. Pick one movement model for the object.
Simple Forward Movement
<?php
declare(strict_types=1);
namespace Game\Scripts;
use Lenga\Engine\Core\Behaviour;
use Lenga\Engine\Core\CharacterController;
use Lenga\Engine\Core\Time;
use Lenga\Engine\Core\Vector3;
final class RunnerController extends Behaviour
{
public float $moveSpeed = 8.0;
private ?CharacterController $controller = null;
public function start(): void
{
$this->controller = $this->gameObject->getComponent(CharacterController::class);
}
public function update(): void
{
if (!$this->controller instanceof CharacterController) {
return;
}
$motion = new Vector3(0.0, 0.0, -1.0);
$motion = Vector3::scaleNew($motion, $this->moveSpeed * Time::deltaTime());
$this->controller->move($motion);
}
}
Keep Movement Ownership Clear
The practical rule is:
Rigidbody3Downs motion for physics-driven bodies.CharacterControllerowns motion for character-style bodies.
When movement feels unpredictable, check that the object is not being moved by both systems at the same time.