SgVehicle

Represents a physics-based vehicle with wheels, steering, and suspension behavior. Provides controls for acceleration, braking, and turning via input or scripting. Useful for driving games or any simulation involving cars or similar machinery.

Inherits from

Usage

To use this class, add the following require at the top of your script:

local SgVehicle = require 'engine/sceneobjects/sgvehicle'

Reference

class SgVehicle
module:
create(options, parent)

Create a new vehicle object in the scenegraph.

Parameters:
  • options (table) – A table of options to fill the parameters

  • parent (SceneObject) – The parent scene object to add this to

Returns:

a promise which will resolve to the created object

Return type:

Promise

Usage:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
-- Options can be omitted. This example shows the defaults,
-- only specify the ones you want different.
SgVehicle:create({
    active = true,
    name = "",
    transform = Transform.new(),
    layers = {0},
    tags = {},
    receiveShadow = false,
    castShadow = false
})
getSpeed()

Get speed in km/h of the vehicle

setSteering(wheels)

Set the steering of the vehicle

Parameters:

wheels (table) – an array of { index, value } objects setting a new steering value for wheels

setBrakes(wheels)

Set the brakes of the vehicle

Parameters:

wheels (table) – an array of { index, value } objects setting a new brake value for wheels

setAcceleration(wheels)

Set the acceleration of the vehicle

Parameters:

wheels (table) – an array of { index, value } objects setting a new acceleration value for wheels

Examples