Class RaycastVehicle

Vehicle helper class that casts rays from the wheel positions towards the ground and applies forces.

Constructors

  • Parameters

    • options: {
          chassisBody: Body;
          indexForwardAxis?: number;
          indexRightAxis?: number;
          indexUpAxis?: number;
      }
      • chassisBody: Body

        The car chassis body.

      • Optional indexForwardAxis?: number

        Index of the forward axis. x=0, y=1, z=2

      • Optional indexRightAxis?: number

        Index of the right axis. x=0, y=1, z=2

      • Optional indexUpAxis?: number

        Index of the up axis. x=0, y=1, z=2

    Returns RaycastVehicle

Properties

chassisBody: Body

The car chassis body.

constraints: Constraint[]

The constraints.

currentVehicleSpeedKmHour: number
indexForwardAxis: number

Index of the forward axis. x=0, y=1, z=2

indexRightAxis: number

Index of the right axis. x=0, y=1, z=2

indexUpAxis: number

Index of the up axis. x=0, y=1, z=2

numWheelsOnGround: number

Number of wheels on the ground.

preStepCallback: (() => void)

Optional pre-step callback.

Type declaration

    • (): void
    • Optional pre-step callback.

      Returns void

sliding: boolean

Will be set to true if the car is sliding.

wheelInfos: WheelInfo[]

The wheels.

world: World

Methods

  • Add the vehicle including its constraints to the world.

    Parameters

    Returns void

  • Add a wheel. For information about the options, see WheelInfo.

    Parameters

    • Optional options: {
          axleLocal?: Vec3;
          axleWorld?: Vec3;
          chassisConnectionPointLocal?: Vec3;
          chassisConnectionPointWorld?: Vec3;
          clippedInvContactDotSuspension?: number;
          customSlidingRotationalSpeed?: number;
          dampingCompression?: number;
          dampingRelaxation?: number;
          deltaRotation?: number;
          directionLocal?: Vec3;
          directionWorld?: Vec3;
          forwardAcceleration?: number;
          frictionSlip?: number;
          isFrontWheel?: boolean;
          maxSuspensionForce?: number;
          maxSuspensionTravel?: number;
          radius?: number;
          rollInfluence?: number;
          rotation?: number;
          sideAcceleration?: number;
          skidInfo?: number;
          slipInfo?: number;
          steering?: number;
          suspensionForce?: number;
          suspensionLength?: number;
          suspensionMaxLength?: number;
          suspensionRelativeVelocity?: number;
          suspensionRestLength?: number;
          suspensionStiffness?: number;
          useCustomSlidingRotationalSpeed?: boolean;
      }
      • Optional axleLocal?: Vec3

        axleLocal

      • Optional axleWorld?: Vec3

        axleWorld

      • Optional chassisConnectionPointLocal?: Vec3

        Connection point, defined locally in the chassis body frame.

      • Optional chassisConnectionPointWorld?: Vec3

        chassisConnectionPointWorld

      • Optional clippedInvContactDotSuspension?: number

        clippedInvContactDotSuspension

        Default

        1
        
      • Optional customSlidingRotationalSpeed?: number

        Speed to apply to the wheel rotation when the wheel is sliding.

        Default

        -0.1
        
      • Optional dampingCompression?: number

        dampingCompression

        Default

        10
        
      • Optional dampingRelaxation?: number

        dampingRelaxation

        Default

        10
        
      • Optional deltaRotation?: number

        deltaRotation

        Default

        0
        
      • Optional directionLocal?: Vec3

        directionLocal

      • Optional directionWorld?: Vec3

        directionWorld

      • Optional forwardAcceleration?: number

        forwardAcceleration

      • Optional frictionSlip?: number

        frictionSlip

        Default

        10.5
        
      • Optional isFrontWheel?: boolean

        isFrontWheel

        Default

        true
        
      • Optional maxSuspensionForce?: number

        maxSuspensionForce

      • Optional maxSuspensionTravel?: number

        Max travel distance of the suspension, in meters.

        Default

        1
        
      • Optional radius?: number

        radius

        Default

        1
        
      • Optional rollInfluence?: number

        rollInfluence

        Default

        0.01
        
      • Optional rotation?: number

        Rotation value, in radians.

        Default

        0
        
      • Optional sideAcceleration?: number

        sideAcceleration

      • Optional skidInfo?: number

        skidInfo

        Default

        0
        
      • Optional slipInfo?: number

        slipInfo

      • Optional steering?: number

        steering

        Default

        0
        
      • Optional suspensionForce?: number

        suspensionForce

        Default

        0
        
      • Optional suspensionLength?: number

        suspensionLength

        Default

        0
        
      • Optional suspensionMaxLength?: number

        suspensionMaxLength

        Default

        2
        
      • Optional suspensionRelativeVelocity?: number

        suspensionRelativeVelocity

        Default

        0
        
      • Optional suspensionRestLength?: number

        suspensionRestLength

        Default

        1
        
      • Optional suspensionStiffness?: number

        suspensionStiffness

        Default

        100
        
      • Optional useCustomSlidingRotationalSpeed?: boolean

        If the customSlidingRotationalSpeed should be used.

        Default

        false
        

    Returns number

  • Set the wheel force to apply on one of the wheels each time step

    Parameters

    • value: number
    • wheelIndex: number

    Returns void

  • Parameters

    Returns number

  • Get the world transform of one of the wheels

    Parameters

    • wheelIndex: number

    Returns Transform

  • Remove the vehicle including its constraints from the world.

    Parameters

    Returns void

  • Set the braking force of a wheel

    Parameters

    • brake: number
    • wheelIndex: number

    Returns void

  • Set the steering value of a wheel.

    Parameters

    • value: number
    • wheelIndex: number

    Returns void

  • Parameters

    • timeStep: number

    Returns void

  • Parameters

    • deltaTime: number

    Returns void

  • Parameters

    • timeStep: number

    Returns void

  • Update one of the wheel transform. Note when rendering wheels: during each step, wheel transforms are updated BEFORE the chassis; ie. their position becomes invalid after the step. Thus when you render wheels, you must update wheel transforms before rendering them. See raycastVehicle demo for an example.

    Parameters

    • wheelIndex: number

      The wheel index to update.

    Returns void

  • Parameters

    Returns void