Skip to main content

Class PrometeoCarController

A physics-based custom car controller adapted from the Prometeo Car Controller asset on the Unity Asset Store.

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

Inheritance​

Implements​

Remarks​

Uses WheelColliders to model per-wheel friction curves, suspension travel, and longitudinal slip independently, producing realistic tyre behaviour under braking, cornering, and road-edge encounters. The wheel arrays are variably sized, so the same controller works for different vehicle configurations (two-axle cars, three-axle trucks, or any other wheel count).

Both player input and AI commands reach the controller through the same IControllable/IMoveable interface, so the same physics behaviour applies whether a human is driving or an AI agent is following a waypoint path.

Properties​

MaxSpeed​

Gets the maximum movement speed of the object in meter per second.

public float MaxSpeed { get; }

Property Value​

float

SteerAmount​

Gets the current steering amount, normalized to the range [-1, 1].

public float SteerAmount { 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.

Remarks​

Steering is derived from the signed angle between the vehicle's forward axis and the local-space direction to the destination, then normalised by the minimum steerable-wheel max angle so the output stays in [-1, 1] regardless of wheel setup.

The slowRadius formula (maxSpeed * (maxSpeed / maxForce + 1) / 2) is a kinematic braking-distance estimate: at maximum deceleration force the vehicle needs approximately v²/(2a) metres to stop from top speed. Within that radius the desired speed is linearly interpolated to zero so the AI decelerates smoothly rather than braking hard at the last moment.

Throttle is clamped to [0, 1] (never negative) because reversing may destabilise the path-following logic; reversing is handled only when the BT explicitly commands it.

GetThrottleScaledSpeedRatio()​

Returns a [0.5, 1] ratio that the PID controller uses to scale its throttle output as the vehicle approaches maximum speed.

public float GetThrottleScaledSpeedRatio()

Returns​

float — A float representing the throttle-scaled speed ratio relative to the maximum forward or reverse speed.

Remarks​

The 0.5 floor prevents the ratio from reaching zero at low speeds, which would cause the PID to output zero throttle and stall. Full throttle authority is preserved up to half the maximum speed; above that the ratio tightens, giving the PID finer control near the speed limit and preventing overshoot.

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

SetSteerInput(float)​

Sets the steering input value.

public void SetSteerInput(float input)

Parameters​

NameTypeDescription
inputfloatThe input value representing steering direction and magnitude.

Remarks​

The input value is clamped between -1 and 1 to ensure valid steering input.

SetThrottleInput(float)​

Sets the throttle input value.

public void SetThrottleInput(float input)

Parameters​

NameTypeDescription
inputfloatThe input value representing the throttle.

Remarks​

The input value is clamped between -1 and 1 to ensure valid throttle input.

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()
  • Remarks
  • Properties
    • MaxSpeed
    • SteerAmount
  • Methods
    • CalculateMoveInput(Vector3)
    • GetThrottleScaledSpeedRatio()
    • Move(Vector2)
    • SetSteerInput(float)
    • SetThrottleInput(float)
    • Stop()