Skip to main content

Class PhysicsBasedCharacterController

A Rigidbody-driven character controller for pedestrian actors, handling movement, slope traversal, custom gravity, and optional context steering.

[RequireComponent(typeof(Rigidbody))]
public class PhysicsBasedCharacterController : MonoBehaviour, IMaxSpeedProvider, IMoveable, IHasUnityContext, IAutoNavigable

Inheritance​

Implements​

Remarks​

A Rigidbody character controller that keeps pedestrians physically consistent with the vehicle simulation and allows the collision detection pipeline to record and log pedestrian-vehicle near-miss events.

Gravity is applied manually via FixedUpdate rather than relying on Rigidbody.useGravity so that the slope-probe logic can counteract gravity on valid slopes, preventing the character from sliding when standing on kerbs or ramps. The SurfaceProbeInfo struct parameterises the maximum traversable angle per-scenario without code changes.

Properties​

MaxSpeed​

The current maximum speed: walking speed if walking (or limited to walking only), otherwise running speed.

public float MaxSpeed { get; }

Property Value​

float

Methods​

CalculateMoveInput(Vector3)​

Calculates the necessary input to move the unit to the destination.

public Vector2 CalculateMoveInput(Vector3 destination)

Parameters​

NameTypeDescription
destinationVector3The destination to move to.

Returns​

Vector2 — The calculated move input.

Move(Vector2)​

Applies a normalised 2D movement input to the unit.

public void Move(Vector2 input)

Parameters​

NameTypeDescription
inputVector2Normalised input vector where x is the lateral/steering axis and y is the forward/throttle axis, both in the range [−1, 1].

SetWalkOnly(bool)​

Enables or disables walking-only mode.

public void SetWalkOnly(bool enable)

Parameters​

NameTypeDescription
enableboolIf true, the character will be limited to walking only.

Stop()​

Brings the unit to a halt, equivalent to Move(Vector2.zero) but may additionally disengage physics forces on the concrete implementation.

public void Stop()