VehicleControllerSettings

Package: Libraries.Game.Scenes · Inherits from: Libraries.Language.Object

VehicleControllerSettings holds every setting of a vehicle controller: a model in a scene that drives as a car. A scene keeps them in the model's Controller block, and the scene editor's Controller section changes them. When a game loads the scene, Build makes the car from them. The car is made of two parts. The body is a plain item with a physics box, which the vehicle drives; it isn't drawn and isn't saved. The model is drawn on the body, as it rides along, and never has physics, so the model's file is used as it is: the model's front can face any of its own four sides (SetFaces), and its origin can be anywhere, since an offset says where it sits from the body's middle. FitToModel works out a starting offset, box and wheels from the model's shape. Lengths are in world units, along the body's own axes: +X along the axles, +Y up and +Z forward. They aren't scaled with the model.

Example Code

use Libraries.Game.Scenes.VehicleControllerSettings
use Libraries.Game.Graphics.Model

VehicleControllerSettings settings
Model car
car:Load("Car/ToyCar.gltf")
settings:SetFaces("-Z")
settings:FitToModel(car)
settings:SetSetting(settings:STIFFNESS, 12)
output settings:ToJson():ToText()

Variables

  • integer LINEAR_DAMPING
  • integer WHEEL_SIDE
  • integer DAMPING_RELAXATION
  • integer MAXIMUM_FORCE
  • integer BOX_WIDTH
  • integer MODEL_OFFSET_Y
  • integer WHEEL_HEIGHT
  • integer FRICTION_SLIP
  • text VEHICLE: The vehicle's type, as the Controller block names it.
  • integer MODEL_OFFSET_Z
  • integer ENGINE_FORCE
  • text DRIVE_ALL: The vehicle's type, as the Controller block names it.
  • integer WHEEL_RADIUS
  • integer MODEL_OFFSET_X: Each number setting has a place in the list below.
  • integer BOX_HEIGHT
  • integer REVERSE_FORCE
  • integer DAMPING_COMPRESSION
  • text DRIVE_REAR
  • integer CAMERA_ABOVE
  • integer REAR_AXLE
  • integer SETTING_COUNT: Which wheels the engine turns.
  • integer FRONT_AXLE
  • integer ROLL_INFLUENCE
  • integer REST_LENGTH
  • integer CAMERA_SMOOTHING
  • integer BRAKE_FORCE
  • integer MASS
  • integer CAMERA_BEHIND
  • text DRIVE_FRONT: Which wheels the engine turns.
  • integer ANGULAR_DAMPING
  • integer THROTTLE_SPEED
  • integer MAXIMUM_TRAVEL
  • integer CAMERA_ANGLE
  • integer STEERING_SPEED
  • integer FRICTION
  • integer BOX_LENGTH
  • integer MAXIMUM_STEERING
  • integer STIFFNESS

Actions

BodyToWorld(Libraries.Interface.Item3D model, Libraries.Compute.Vector3 point)

This action turns a point from the body's axes to the world's, as the body is turned. The point isn't moved.

Parameters

Returns

Libraries.Compute.Vector3: The point in the world.

Build(Libraries.Interface.Item3D model, Libraries.Game.Layer3D layer)

This action makes the car for a model: its body, the vehicle with four wheels, and the behavior that drives it with W, S, A, D and Space. The body and vehicle go in the layer; the model is drawn on the body from then on, and loses any physics of its own. If the camera follows, the layer's camera follows the body.

Parameters

Returns

Libraries.Game.Scenes.SceneController: What was made.

Copy()

This action returns a copy of these settings, such as to change them without changing these.

Returns

Libraries.Game.Scenes.VehicleControllerSettings: The copy.

FitToModel(Libraries.Game.Graphics.Model model)

This action sets the offset, box and wheels from a model's shape, as a starting point: the body's middle at the middle of the model's shape, a box lower and shorter than the shape so it clears slopes, and four wheels near the shape's corners whose bottoms meet the shape's bottom when the car's weight is on them. SetFaces should be set first. Other settings are kept. A model with no shape changes nothing.

Parameters

Returns

boolean: True if the settings were fitted.

FromJson(Libraries.Data.Formats.JavaScriptObjectNotation json)

This action reads the settings from a scene's Controller block. A setting the block doesn't have keeps its value.

Parameters

GetBodyPosition(Libraries.Interface.Item3D model)

This action returns where the body's middle starts for a model: the model's origin, less the offset along the body's axes.

Parameters

Returns

Libraries.Compute.Vector3: The body's middle, in world units.

GetBodyRotation(Libraries.Interface.Item3D model)

This action returns how the body is turned for a model: upright, with its +Z the way the model's front faces, level with the ground. Only the rotation part is set.

Parameters

Returns

Libraries.Compute.Matrix4: The body's rotation.

GetDrive()

This action returns which wheels the engine turns.

Returns

text: DRIVE_FRONT, DRIVE_REAR or DRIVE_ALL.

GetFaces()

This action returns which of its own sides the model's front faces.

Returns

text: "+Z", "-Z", "+X" or "-X".

GetFacingDirection()

This action returns the way the model's front faces, along the model's own axes, from SetFaces.

Returns

Libraries.Compute.Vector3: A direction of length 1.

GetFollowPosition(Libraries.Interface.Item3D model)

This action returns where the game's camera starts when it follows the car: CAMERA_BEHIND behind the body's middle, turned CAMERA_ANGLE degrees around it, and CAMERA_ABOVE above it, as Camera's Follow places it.

Parameters

Returns

Libraries.Compute.Vector3: The camera's place, in the world.

GetModelOffset()

This action returns where the model's origin sits from the body's middle, along the body's axes.

Returns

Libraries.Compute.Vector3: The offset.

GetRestingCompression()

This action returns how far a wheel's spring is pressed while the car stands still: a quarter of its weight over its stiffness.

Returns

number: The distance, in world units.

GetSetting(integer which)

This action returns a number setting, such as STIFFNESS.

Parameters

  • which integer: The setting, such as STIFFNESS.

Returns

number: The value.

GetSettingCount()

This action returns how many number settings there are.

Returns

integer: SETTING_COUNT.

GetSettingGroup(integer which)

This action returns the group a number setting is saved in, such as "Suspension".

Parameters

  • which integer: The setting.

Returns

text: The group.

GetSettingName(integer which)

This action returns a number setting's name, as it is saved, such as "Stiffness".

Parameters

  • which integer: The setting.

Returns

text: The name.

GetWheelMount(integer wheel)

This action returns a wheel's mount point, along the body's axes. The wheels are 0 front left, 1 front right, 2 rear left and 3 rear right.

Parameters

  • wheel integer: The wheel, from 0 to 3.

Returns

Libraries.Compute.Vector3: The point, from the body's middle.

IsCameraFollowing()

This action returns whether the game's camera follows the vehicle.

Returns

boolean: True if the camera follows it.

IsDriveWheel(integer wheel)

This action returns true if the engine turns a wheel.

Parameters

  • wheel integer: The wheel, from 0 to 3.

Returns

boolean: True if it drives.

SetCameraFollowing(boolean follows)

This action sets whether the game's camera follows the vehicle, with the CAMERA_BEHIND, CAMERA_ABOVE and CAMERA_SMOOTHING settings.

Parameters

  • follows boolean: True for the camera to follow it.

SetDrive(text wheels)

This action sets which wheels the engine turns. Anything else is taken as the rear wheels.

Parameters

  • wheels text: DRIVE_FRONT, DRIVE_REAR or DRIVE_ALL.

SetFaces(text side)

This action sets which of its own sides the model's front faces, so the model can be used as its file has it. Anything else is taken as +Z.

Parameters

  • side text: "+Z", "-Z", "+X" or "-X".

SetFollowFrom(Libraries.Interface.Item3D model, Libraries.Compute.Vector3 position)

This action sets CAMERA_BEHIND, CAMERA_ABOVE and CAMERA_ANGLE from a place for the following camera, such as where the game camera was moved to in the scene editor.

Parameters

SetSetting(integer which, number value)

This action sets a number setting, such as STIFFNESS.

Parameters

  • which integer: The setting, such as STIFFNESS.
  • value number: The new value.

ToJson()

This action writes the settings as a scene's Controller block.

Returns

Libraries.Data.Formats.JavaScriptObjectNotation: The block.

Inherited Actions

3 actions from Libraries.Language.Object