Skip to main content

Class PlayerPedestrianDriver

Translates Unity Input System values from PlayerController into movement and rotation commands for a Unity CharacterController-based pedestrian pawn.

[RequireComponent(typeof(CharacterController))]
public class PlayerPedestrianDriver : MonoBehaviour, IControllable, IMoveable, IHasUnityContext, IWalkable

Inheritance​

Implements​

Remarks​

It utilizes a CharacterController instead of a Rigidbody because the player pawn requires frame-accurate, input-responsive movement — a Rigidbody accumulates forces across frames and can introduce lag or drift that makes character control feel imprecise. The player pawn also does not need to receive physics impulses from vehicle collisions: the AI-driven PhysicsBasedCharacterController uses a Rigidbody specifically to participate in the collision pipeline so near-miss events can be detected and logged, but the player pawn has no such requirement.

The WalkModeInputClamp symmetrically clamps raw joystick or keyboard input so that holding the walk modifier always produces a walking gait regardless of how far the player pushes the stick, making pace control consistent across input devices.

Methods​

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].

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()

Walk(bool)​

Sets whether the entity should walk instead of run.

public void Walk(bool input)

Parameters​

NameTypeDescription
inputboolIf true, the entity will walk; otherwise, it will run.