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_DAMPINGinteger WHEEL_SIDEinteger DAMPING_RELAXATIONinteger MAXIMUM_FORCEinteger BOX_WIDTHinteger MODEL_OFFSET_Yinteger WHEEL_HEIGHTinteger FRICTION_SLIPtext VEHICLE: The vehicle's type, as the Controller block names it.integer MODEL_OFFSET_Zinteger ENGINE_FORCEtext DRIVE_ALL: The vehicle's type, as the Controller block names it.integer WHEEL_RADIUSinteger MODEL_OFFSET_X: Each number setting has a place in the list below.integer BOX_HEIGHTinteger REVERSE_FORCEinteger DAMPING_COMPRESSIONtext DRIVE_REARinteger CAMERA_ABOVEinteger REAR_AXLEinteger SETTING_COUNT: Which wheels the engine turns.integer FRONT_AXLEinteger ROLL_INFLUENCEinteger REST_LENGTHinteger CAMERA_SMOOTHINGinteger BRAKE_FORCEinteger MASSinteger CAMERA_BEHINDtext DRIVE_FRONT: Which wheels the engine turns.integer ANGULAR_DAMPINGinteger THROTTLE_SPEEDinteger MAXIMUM_TRAVELinteger CAMERA_ANGLEinteger STEERING_SPEEDinteger FRICTIONinteger BOX_LENGTHinteger MAXIMUM_STEERINGinteger 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
modelLibraries.Interface.Item3D: The model, placed and turned as in the scene.pointLibraries.Compute.Vector3: A point along the body's axes, from its middle.
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
modelLibraries.Interface.Item3D: The model, placed and turned as in the scene, in the layer.layerLibraries.Game.Layer3D: The model's layer.
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
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
modelLibraries.Game.Graphics.Model: The model, placed and turned as in the scene.
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
jsonLibraries.Data.Formats.JavaScriptObjectNotation: The block.
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
modelLibraries.Interface.Item3D: The model, placed and turned as in the scene.
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
modelLibraries.Interface.Item3D: The model, placed and turned as in the scene.
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
modelLibraries.Interface.Item3D: The model, placed and turned as in the scene.
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
whichinteger: 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
whichinteger: 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
whichinteger: 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
wheelinteger: 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
wheelinteger: 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
followsboolean: 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
wheelstext: 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
sidetext: "+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
modelLibraries.Interface.Item3D: The model, placed and turned as in the scene.positionLibraries.Compute.Vector3: The camera's place, in the world.
SetSetting(integer which, number value)
This action sets a number setting, such as STIFFNESS.
Parameters
whichinteger: The setting, such as STIFFNESS.valuenumber: The new value.
ToJson()
This action writes the settings as a scene's Controller block.
Returns
Libraries.Data.Formats.JavaScriptObjectNotation: The block.