Camera Controllers
Gorilla3D provides pre-built camera and character controllers for common 3D navigation patterns. These components handle keyboard, mouse, and gamepad input to move and rotate a camera or character in 3D space, saving you from implementing movement logic from scratch.
Table of Contents
- Overview
- Class Hierarchy
- Character Controller (Base)
- First-Person Controller
- Third-Person Controller
- Trigger Points
- Combining with Input System
- Best Practices
Overview
All camera controllers require a TGorillaInputController to receive input events. The inheritance hierarchy is:
| Controller | Class | Purpose |
|---|---|---|
| Character Controller | TGorillaCharacterController |
Abstract base with states, hotkeys, movement, jumping, crouching, crawling |
| First-Person Controller | TGorillaFirstPersonController |
Ego-perspective movement with mouse look |
| Third-Person Controller | TGorillaThirdPersonController |
Orbit camera around a character |
Additionally, the Trigger Point Manager (TGorillaTriggerPointManager) lets you define interactive 3D points that react when the player looks at or approaches them.
Class Hierarchy
TDummy
└── TGorillaCharacterController (abstract base)
└── TGorillaFirstPersonController (first-person / ego)
└── TGorillaThirdPersonController (third-person / orbit)
All controllers are TDummy descendants, meaning they are 3D transform nodes. The camera becomes a child of the controller, and movement is applied to the controller itself.
Character Controller (Base)
TGorillaCharacterController is the abstract base class that provides the common functionality for all character controllers. You do not use this class directly — use TGorillaFirstPersonController or TGorillaThirdPersonController instead.
States
The controller maintains a set of states describing what the character is doing:
| State | Description |
|---|---|
fpIdle |
Character is not moving |
fpMoving |
Character is moving (WASD or thumbstick) |
fpBoost |
Running / sprinting (Shift held) |
fpCrouching |
Crouching (reduced height and speed) |
fpCrawling |
Crawling (further reduced height and speed) |
fpJumping |
Currently in a jump animation |
fpAiming |
Aiming mode active |
fpPushing |
Pushing action active |
fpPulling |
Pulling action active |
States can be combined — for example, a character can be [fpMoving, fpCrouching] simultaneously.
// Check current state
if fpMoving in FirstPersonController1.States then
ShowMessage('Character is moving');
// Manually add/remove states
FirstPersonController1.AddState(fpBoost);
FirstPersonController1.RemoveState(fpBoost);
HotKeys
The controller automatically registers default hotkeys when linked to an input controller:
| Action | Keyboard | Gamepad |
|---|---|---|
| Move Forward | W | Left Thumbstick Up |
| Move Backward | S | Left Thumbstick Down |
| Move Left | A | Left Thumbstick Left |
| Move Right | D | Left Thumbstick Right |
| Jump | Space | A Button |
| Crouch | C | B Button |
| Boost/Run | Left Shift | Left Trigger |
| Aim | Right Mouse | Right Trigger |
You can access and customize individual hotkeys via the HotKey indexed property:
// Access a specific hotkey
var LHotKey := FirstPersonController1.HotKey[OnCharacterMoveForward];
Movement Properties
| Property | Type | Default | Description |
|---|---|---|---|
Speed |
Single | 0.25 | Base movement speed |
SidewayRotationSpeed |
Single | 1.0 | Rotation speed when using sideway keys |
CrouchingSpeedReduction |
Single | 0.75 | Speed multiplier when crouching (0.0–1.0) |
CrawlingSpeedReduction |
Single | 0.9 | Speed multiplier when crawling (0.0–1.0) |
RunningSpeedBoost |
Single | 2.0 | Speed multiplier when boosting (1–1000) |
JumpingHeight |
Single | 2.0 | Height of jump |
CrouchingHeight |
Single | 0.5 | How low the character crouches |
CrawlingHeight |
Single | 0.25 | How low the character crawls |
JumpingAnimationTime |
Single | — | Duration of jump animation in seconds |
CrouchingAnimationTime |
Single | — | Duration of crouch transition |
CrawlingAnimationTime |
Single | — | Duration of crawl transition |
MoveSideways |
Boolean | — | If true, A/D keys strafe; if false, A/D keys rotate |
RotateOnSideways |
Boolean | — | Rotate the controller on sideway movement |
LockXAxis |
Boolean | False | Prevent movement on X axis |
LockYAxis |
Boolean | False | Prevent movement on Y axis |
LockZAxis |
Boolean | False | Prevent movement on Z axis |
CameraYAngleLimit |
TPointF | (-180, 180) | Min/max horizontal rotation in degrees |
CameraXAngleLimit |
TPointF | (-45, 45) | Min/max vertical rotation in degrees |
Events
| Event | Type | Description |
|---|---|---|
OnIdle |
TOnCharacterControllerEvent |
Fired when controller switches to idle |
OnMove |
TOnCharacterControllerMoveEvent |
Fired on any movement (provides direction and speed) |
OnRotate |
TOnCharacterControllerRotateEvent |
Fired on camera rotation (provides quaternion and delta) |
OnBoost |
TOnCharacterControllerEvent |
Fired when boost activates/deactivates |
OnCrouch |
TOnCharacterControllerEvent |
Fired on crouch toggle |
OnCrawl |
TOnCharacterControllerEvent |
Fired on crawl toggle |
OnJump |
TOnCharacterControllerEvent |
Fired when jumping |
OnAim |
TOnCharacterControllerEvent |
Fired on aim toggle |
OnPush |
TOnCharacterControllerEvent |
Fired on push action |
OnPull |
TOnCharacterControllerEvent |
Fired on pull action |
OnCustomAction |
TOnCharacterControllerHotKeyTriggered |
Fired by custom hotkeys |
OnClick |
TOnCharacterControllerHotKeyTriggered |
Fired by mouse button clicks |
OnHotKey |
TOnCharacterControllerHotKeyTriggered |
General hotkey trigger callback |
OnTriggerPoint |
TOnCharacterControllerTriggerPoint |
Fired when a trigger point is detected |
OnChangeSize |
TNotifyEvent |
Fired when character height changes (crouch/crawl) |
First-Person Controller
TGorillaFirstPersonController implements ego-perspective movement. The camera is placed at the character's eye level and rotates with mouse movement. WASD keys (or gamepad thumbstick) move the character forward, backward, and sideways.
First-Person Setup
Design-Time
- Drop a
TGorillaInputControlleronto your form - Drop a
TGorillaFirstPersonControlleronto your viewport - Set
InputControllerto link to the input controller - Set
Camerato link to yourTGorillaCamera - Configure speed, drag modes, and angle limits as needed
Runtime
var
InputCtrl: TGorillaInputController;
FPController: TGorillaFirstPersonController;
begin
// Create input controller
InputCtrl := TGorillaInputController.Create(Self);
InputCtrl.Viewport := GorillaViewport1;
// Create first-person controller
FPController := TGorillaFirstPersonController.Create(Self);
FPController.Parent := GorillaViewport1;
FPController.InputController := InputCtrl;
FPController.Camera := GorillaCamera1;
FPController.Speed := 0.35;
FPController.ShowCursor := False;
end;
Mouse Configuration
| Property | Type | Default | Description |
|---|---|---|---|
MouseControllerSpeed |
Single | 0.075 | Sensitivity of mouse look rotation |
GamePadThumbstickSpeed |
Single | 0.5 | Sensitivity of gamepad thumbstick rotation |
ShowCursor |
Boolean | True | Show or hide the mouse cursor |
UseCameraDirection |
Boolean | True | Use camera direction for movement; if false, uses controller direction |
Rotation and Movement Drag Modes
By default, mouse movement always rotates the camera. You can require a mouse button to be held for rotation or movement:
// Only rotate when right mouse button is held
FPController.RotationDragMode := True;
FPController.RotationDragModeButton := TGorillaMouseState.RButtonDown;
// Enable drag-to-move with middle mouse button
FPController.MovementDragMode := True;
FPController.MovementDragModeButton := TGorillaMouseState.MButtonDown;
// Optionally invert drag movement axes
FPController.InvertMovementDragModeXAxis := True;
FPController.InvertMovementDragModeYAxis := False;
Additional properties:
| Property | Type | Description |
|---|---|---|
RotateAroundCenter |
Boolean | Rotate the controller component itself instead of free camera rotation |
UseDefaultBehaviour |
Boolean | Enable/disable built-in hotkey behavior |
UseDefaultMovement |
Boolean | Enable/disable built-in WASD/gamepad movement (does not affect camera rotation) |
First-Person Example
procedure TForm1.FormCreate(Sender: TObject);
begin
// Setup viewport and camera
GorillaViewport1.UsingDesignCamera := False;
// Create input controller
FInputCtrl := TGorillaInputController.Create(Self);
FInputCtrl.Viewport := GorillaViewport1;
// Create first-person controller
FFPCtrl := TGorillaFirstPersonController.Create(Self);
FFPCtrl.Parent := GorillaViewport1;
FFPCtrl.Position.Y := -1.8; // eye height
FFPCtrl.InputController := FInputCtrl;
FFPCtrl.Camera := GorillaCamera1;
// Configure movement
FFPCtrl.Speed := 0.3;
FFPCtrl.RunningSpeedBoost := 2.5;
FFPCtrl.ShowCursor := False;
FFPCtrl.CameraXAngleLimit := PointF(-80, 80);
// React to movement
FFPCtrl.OnMove := procedure(ASender: TObject;
AKind: TGorillaCharacterControllerHotKey; ADir: TPoint3D;
ACurrentSpeed: Single)
begin
// e.g., play footstep sounds, update animation
end;
end;
Third-Person Controller
TGorillaThirdPersonController extends the first-person controller to provide an orbital camera that rotates around the character. The camera is placed as a child of the controller at a configurable distance. Mouse movement orbits the camera, and the scroll wheel zooms in/out.
Third-Person Setup
var
TPController: TGorillaThirdPersonController;
begin
TPController := TGorillaThirdPersonController.Create(Self);
TPController.Parent := GorillaViewport1;
TPController.InputController := InputCtrl;
TPController.Camera := GorillaCamera1;
// Camera distance limits (absolute values)
TPController.CameraZLimit := PointF(-1, -25); // min 1, max 25 units away
TPController.MouseWheelSpeed := 1.5;
end;
Orbit Camera
The third-person controller places the camera behind and above the character. Mouse drag orbits the camera around the character, and the scroll wheel adjusts distance.
| Property | Type | Default | Description |
|---|---|---|---|
MouseWheelSpeed |
Single | 1.0 | Speed of mouse wheel zoom (0–10) |
CameraZLimit |
TPointF | (-1, -25) | Camera distance limits: X = closest, Y = farthest |
Defaults changed from FirstPerson:
UseCameraDirectiondefaults toFalse(orbit mode)RotateOnSidewaysdefaults toTrueMoveSidewaysdefaults toFalseCameraYAngleLimitdefaults to (-180, 180)CameraXAngleLimitdefaults to (-45, 45)
Third-Person Example
procedure TForm1.FormCreate(Sender: TObject);
begin
GorillaViewport1.UsingDesignCamera := False;
FInputCtrl := TGorillaInputController.Create(Self);
FInputCtrl.Viewport := GorillaViewport1;
// Create third-person controller at character position
FTPCtrl := TGorillaThirdPersonController.Create(Self);
FTPCtrl.Parent := GorillaViewport1;
FTPCtrl.Position.Point := Point3D(0, -1, 0);
FTPCtrl.InputController := FInputCtrl;
FTPCtrl.Camera := GorillaCamera1;
// Orbit configuration
FTPCtrl.CameraZLimit := PointF(-2, -15);
FTPCtrl.MouseWheelSpeed := 2;
FTPCtrl.RotationDragMode := True;
FTPCtrl.RotationDragModeButton := TGorillaMouseState.RButtonDown;
FTPCtrl.Speed := 0.2;
end;
Trigger Points
TGorillaTriggerPointManager manages a collection of trigger points in 3D space. When combined with a character controller, it automatically checks whether the player is looking at or standing near a trigger point, and fires events accordingly.
Static vs Dynamic
| Kind | Description |
|---|---|
StaticTriggerPoint |
Fixed 3D world coordinate that never moves |
DynamicTriggerPoint |
Follows a linked TControl3D, with the trigger point position as offset |
Trigger Point Setup
var
TriggerMgr: TGorillaTriggerPointManager;
TP: TGorillaTriggerPoint;
begin
TriggerMgr := TGorillaTriggerPointManager.Create(Self);
TriggerMgr.Enabled := True;
// Add a static trigger point
TP := TriggerMgr.AddTriggerPoint(
'Door', // Name
Point3D(5, -1, 3), // World position
5.0, // Tolerance (how close the view ray must be)
10.0 // Maximum detection distance
);
// Add a dynamic trigger point following a 3D object
TriggerMgr.AddTriggerPoint(
'NPC', // Name
SomeCharacterModel, // TControl3D to follow
Point3D(0, -1, 0), // Offset from control
3.0, // Tolerance
8.0 // Distance
);
// Link to character controller
FirstPersonController1.TriggerPoints := TriggerMgr;
end;
Trigger Point Properties
| Property | Type | Description |
|---|---|---|
Enabled |
Boolean | Activate or deactivate the trigger point |
Kind |
TGorillaTriggerPointKind |
StaticTriggerPoint or DynamicTriggerPoint |
LookInDirection |
Boolean | If true, triggers only when looking toward it; if false, triggers by proximity |
Control |
TControl3D | Linked 3D control for dynamic trigger points |
Position |
TPosition3D | World position (static) or offset (dynamic) |
Tolerance |
Single | Allowed deviation between view direction and point (0–100) |
Distance |
Single | Maximum detection distance (0–1000) |
Tag |
Integer | Custom integer data |
Data |
TValue | Custom data field (any type via RTTI) |
TriggerCount |
Integer | How many times the point has been triggered (read-only) |
Trigger Point Events
Each trigger point can have individual events:
TP.OnTriggered := procedure(ASender: TGorillaTriggerPointManager;
const APos, AViewDir: TPoint3D; const APoint: TGorillaTriggerPoint;
const ADistance: Single)
begin
ShowHint('Press E to open ' + APoint.DisplayName);
end;
TP.OnUnTriggered := procedure(ASender: TGorillaTriggerPointManager;
const APos, AViewDir: TPoint3D; const APoint: TGorillaTriggerPoint;
const ADistance: Single)
begin
HideHint();
end;
You can also query trigger points manually:
var
LPoint: TGorillaTriggerPoint;
LDistance: Single;
begin
if TriggerMgr.ClosestTriggerPoint(CameraPos, CameraDir, LPoint, LDistance) then
Label1.Text := Format('Nearest: %s (%.1f m)', [LPoint.DisplayName, LDistance]);
end;
Trigger Point Example
procedure TForm1.FormCreate(Sender: TObject);
begin
FTriggerMgr := TGorillaTriggerPointManager.Create(Self);
// Door trigger - activates when looking at it within 8 units
var LDoor := FTriggerMgr.AddTriggerPoint('Door', Point3D(10, -1, 0), 3.0, 8.0);
LDoor.LookInDirection := True;
// Proximity trigger - activates when nearby regardless of view direction
var LZone := FTriggerMgr.AddTriggerPoint('SafeZone', Point3D(0, 0, 20), 5.0, 5.0);
LZone.LookInDirection := False;
// Link to controller
FFPCtrl.TriggerPoints := FTriggerMgr;
FFPCtrl.OnTriggerPoint := HandleTriggerPoint;
end;
procedure TForm1.HandleTriggerPoint(ASender: TObject;
AManager: TGorillaTriggerPointManager; APt: TGorillaTriggerPoint;
ADist: Single);
begin
if APt.DisplayName = 'Door' then
OpenDoor();
end;
Combining with Input System
The character controllers work best when combined with the TGorillaInputController. The input controller provides the raw input events, while the character controller interprets them as movement, rotation, and actions.
// The input controller handles raw input
InputCtrl := TGorillaInputController.Create(Self);
InputCtrl.Viewport := GorillaViewport1;
// The character controller interprets input as 3D movement
FPCtrl := TGorillaFirstPersonController.Create(Self);
FPCtrl.Parent := GorillaViewport1;
FPCtrl.InputController := InputCtrl;
FPCtrl.Camera := GorillaCamera1;
// You can also link an AudioManagerController for automatic sound playback
FPCtrl.AudioManagerController := AudioMgrCtrl;
For custom hotkeys beyond the built-in defaults, add them via the input controller and listen to the OnCustomAction event:
FPCtrl.OnCustomAction := procedure(ASender: TObject;
const AKind: TGorillaCharacterControllerHotKey;
const AHotKey: TGorillaHotKeyItem;
const AStates: TGorillaCharacterControllerStates;
const AMode: TGorillaInputMode)
begin
if AHotKey.Name = 'Interact' then
DoInteraction();
end;
Best Practices
- Always link an InputController — the character controllers do nothing without one.
- Set
UsingDesignCamera := Falseon the viewport when using a character controller camera. - Use angle limits (
CameraXAngleLimit,CameraYAngleLimit) to prevent the camera from flipping. - For third-person, set
RotationDragMode := Trueso orbiting only happens when dragging, leaving the cursor free for UI interaction. - Use
UseDefaultMovement := Falseif you need custom movement logic (e.g., physics-based) while keeping the camera rotation behavior. - Trigger points with
LookInDirection := Falseare useful for area triggers (safe zones, damage zones) where proximity is sufficient. - Combine with physics by listening to
OnMoveand applying forces to a physics body instead of letting the controller move directly.