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 : CharacterComponentInheritance: 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:
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.x→Vector3.x(strafe)moveInput.y→Vector3.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
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().
moveInput
Vector2
Movement input (x = strafe, y = forward)
MoveTo
Moves the character towards a world-space target position. Delegates to CharacterMotor.MoveTo().
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().
lookInput
Vector2
Look input (x = horizontal rotation)
RotateTowards
Rotates the character to face a world-space direction. Delegates to CharacterMotor.RotateTowards().
direction
Vector3
World-space direction to face
RotateTo
Rotates the character to face a world-space target position. Delegates to CharacterMotor.RotateTo().
target
Vector3
World-space position to face
LookAt
Points the camera at a world-space target. Delegates to CharacterCamera.LookAt().
target
Vector3
World-space position to look at
LookTowards
Points the camera in a world-space direction. Delegates to CharacterCamera.LookTowards().
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.
enableSprint
bool
true to sprint, false for normal speed
SetWalk
Toggles walk mode. When enabled, the motor uses WalkSpeed; when disabled, reverts to MoveSpeed.
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().
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
SetSprint and SetWalk override each other Both methods set the motor's currentSpeed. Calling SetSprint(true) then SetWalk(true) will result in walk speed. The last call wins. There is no combined sprint+walk state.
MoveBy expects normalized-range input The motor clamps the delta magnitude to 1.0, but passing large values in MoveBy() will still result in max-speed movement. The input should be in the range [-1, 1] per axis.
Examples
Player Input Handling
AI Navigation
See Also
CharacterMotor — the motor that executes movement and rotation
CharacterComponent — abstract base class
Character — the owning entity
Controller Overview — subfolder overview
Last updated