CharacterController

High-level command facade that translates player input and AI directives into calls on the character's motor, camera, interactor, and inventory components. This is the primary API for controlling a character from input systems or AI behaviour trees.

Definition

Namespace: Paragon.Townskeep.CharacterSystem Assembly: Townskeep.dll

[Serializable]
public class CharacterController : CharacterComponent

Inheritance: CharacterComponent → CharacterController

Remarks

CharacterController follows the facade pattern — it does not contain movement or physics logic itself. Instead, it delegates to the appropriate sibling component:

Domain
Delegated To

Movement & rotation

CharacterMotor

Camera look

CharacterCamera

Interactions

CharacterInteractor

Inventory switching

CharacterInventory

Input Translation

Movement input arrives as Vector2 (from gamepad sticks or WASD) and is converted to Vector3 for the motor. The controller maps:

  • moveInput.xVector3.x (strafe)

  • moveInput.yVector3.z (forward/backward)

Initialization

On OnInitialize(), the controller caches references to the motor, camera, interactor, and inventory components from the owning character. These cached references are used for all subsequent calls.

Quick Lookup

Goal
How

Move from input axes

controller.MoveBy(new Vector2(h, v))

Move to world position

controller.MoveTo(targetPos)

Rotate from input axis

controller.RotateBy(new Vector2(mouseX, 0))

Face a direction

controller.RotateTowards(direction)

Face a position

controller.RotateTo(targetPos)

Look camera at target

controller.LookAt(targetPos)

Look camera in direction

controller.LookTowards(direction)

Jump

controller.Jump()

Sprint

controller.SetSprint(true)

Walk

controller.SetWalk(true)

Interact

controller.Interact(trigger)

Cancel interaction

controller.CancelInteraction()

Next inventory slot

controller.SwitchNextItem()

Previous inventory slot

controller.SwitchPreviousItem()

Methods

MoveBy

Moves the character by a 2D input vector. Converts Vector2(x, y) to Vector3(x, 0, y) and delegates to CharacterMotor.MoveBy().

Parameter
Type
Description

moveInput

Vector2

Movement input (x = strafe, y = forward)

MoveTo

Moves the character towards a world-space target position. Delegates to CharacterMotor.MoveTo().

Parameter
Type
Description

targetPosition

Vector3

World-space target position

RotateBy

Rotates the character by a 2D input vector. Uses lookInput.x as the rotation angle. Delegates to CharacterMotor.RotateBy().

Parameter
Type
Description

lookInput

Vector2

Look input (x = horizontal rotation)

RotateTowards

Rotates the character to face a world-space direction. Delegates to CharacterMotor.RotateTowards().

Parameter
Type
Description

direction

Vector3

World-space direction to face

RotateTo

Rotates the character to face a world-space target position. Delegates to CharacterMotor.RotateTo().

Parameter
Type
Description

target

Vector3

World-space position to face

LookAt

Points the camera at a world-space target. Delegates to CharacterCamera.LookAt().

Parameter
Type
Description

target

Vector3

World-space position to look at

LookTowards

Points the camera in a world-space direction. Delegates to CharacterCamera.LookTowards().

Parameter
Type
Description

direction

Vector3

World-space direction to look towards

Jump

Makes the character jump. Delegates to CharacterMotor.Jump(). Only works when grounded (checked by motor).

SetSprint

Toggles sprint mode. When enabled, the motor uses SprintSpeed; when disabled, reverts to MoveSpeed.

Parameter
Type
Description

enableSprint

bool

true to sprint, false for normal speed

SetWalk

Toggles walk mode. When enabled, the motor uses WalkSpeed; when disabled, reverts to MoveSpeed.

Parameter
Type
Description

enableWalk

bool

true to walk, false for normal speed

Interact

Attempts to interact with a trigger in the character's view. Delegates to CharacterInteractor.TryInteractInView().

Parameter
Type
Description

trigger

InteractionTrigger

The interaction trigger to attempt

CancelInteraction

Cancels the current interaction. Delegates to CharacterInteractor.CancelInteraction().

SwitchNextItem

Switches to the next inventory slot. Delegates to CharacterInventory.SwitchNextSlot().

SwitchPreviousItem

Switches to the previous inventory slot. Delegates to CharacterInventory.SwitchPreviousSlot().

Common Pitfalls

circle-exclamation
circle-exclamation

Examples

Player Input Handling

AI Navigation

See Also

Last updated