Vehicle

https://i.imgur.com/IzVg8VU.jpg

Vehicles are 4-wheeled entities which Characters can possesses and drive. Any Skeletal Mesh can be used to create a Vehicle, although only Skeletal Meshes with Wheels bones can use the built-in feature of animated Wheels.

Note

Currently only 4-Wheeled vehicles is supported.

Tip

Please take a look at our Default’s Vehicle package with all built-in Vehicles already properly configured and ready to use: https://github.com/nanos-world/nanos-world-vehicles.

Usage

-- Spawns a SUV Vehicle
local vehicle = Vehicle(Vector(0, 0, 100), Rotator(), "NanosWorld::SK_SUV", 0, true, false, true, "NanosWorld::A_Vehicle_Engine_14")

-- Configure it's Engine Speed and Steering Wheel location
vehicle:SetEngineSetup(4500)
vehicle:SetSteeringWheelSetup(Vector(0, 20, 131), 26)

-- Configures each Wheel
vehicle:SetWheel(0, "Wheel_Front_Left",  35, 22, 50, 20, 0.25, 2, 17, 1000, 50, 50, 10)
vehicle:SetWheel(1, "Wheel_Front_Right", 35, 22, 50, 20, 0.25, 2, 17, 1000, 50, 50, 10)
vehicle:SetWheel(2, "Wheel_Rear_Left",   35, 22,  0, 20, 0.25, 2, 17, 1000, 50, 50, 10)
vehicle:SetWheel(3, "Wheel_Rear_Right",  35, 22,  0, 20, 0.25, 2, 17, 1000, 50, 50, 10)

-- Adds 4 Doors/Seats
vehicle:SetDoor(0, Vector( 22, -80, 120), Vector(-18, -47, 110), Rotator(0, 0, 15), 75, -150)
vehicle:SetDoor(1, Vector( 22,  80, 120), Vector( 5,   39,  90), Rotator(0, 0,  0), 60,  150)
vehicle:SetDoor(2, Vector(-80, -80, 120), Vector(-60, -39,  90), Rotator(0, 0,  0), 60, -150)
vehicle:SetDoor(3, Vector(-80,  80, 120), Vector(-60,  39,  90), Rotator(0, 0,  0), 60,  150)

-- Make it ready (so clients only create Physics once and not for each function call above)
vehicle:RecreatePhysics()

Constructor Parameters

Type

Name

Default

Vector

Location

Vector(0, 0, 0)

Rotator

Rotation

Rotation(0, 0, 0)

string

ModelName (Skeletal Mesh)

number

CollisionType

0 (Normal)

boolean

GravityEnabled

true

boolean

AutoCreatePhysics (can be disabled to improve performance when setting several configs. Must call RecreatePhysics() after all)

true

boolean

AutoUnflip (auto rotates the vehicle if flipped)

true

string

EngineSoundAsset

NanosWorld::A_Vehicle_Engine_01

string

HornSoundAsset

NanosWorld::A_Vehicle_Horn_Toyota

string

BrakeSoundAsset

NanosWorld::A_Vehicle_Brake

string

EngineStartSoundAsset

NanosWorld::A_Car_Engine_Start

string

VehicleDoorSoundAsset

NanosWorld::A_Vehicle_Door

Note

Most of the functions below will reset the vehicle Physics State (automatically), which means the vehicle will stop immediately if moving.

Functions

Returns

Name

Description

server-only-label

AddStaticMeshAttached(string ID, string StaticMeshPath, string Socket = “”, Vector RelativeLocation = Vector(), Rotator RelativeRotation = Rotator())

Spawns and Attaches a StaticMesh into this Vehicle in a Socket with relative Location and Rotation. Uses a custom ID to be used for removing it further

server-only-label

Horn(boolean Bool)

Starts or stops the vehicles horn

server-only-label

RecreatePhysics()

Recreate the Vehicle Physics (call this after configuring the vehicle if using AutoCreatePhysics = false)

server-only-label

RemoveStaticMeshAttached(string ID)

Removes, if existing, a StaticMesh from this Vehicle given it’s custom ID

server-only-label

SetDifferentialSetup(number DifferentialType = 0, number FrontRearSplit = 0.45, number FrontLeftRightSplit = 0.5, number RearLeftRightSplit = 0.5, number CenterBias = 1.3, number FrontBias = 1.3, number RearBias = 1.3)

Configures the Vehicle Differential. Check the page bottom to see each property explanation

server-only-label

SetEngineSetup(number MaxRPM = 4500, number MOI = 1, number DampingRateFullThrottle = 0.15, number DampingRateZeroThrottleClutchEngaged = 2, number DampingRateZeroThrottleClutchDisengaged = 0.35)

Configures the Vehicle Engine. Check the page bottom to see each property explanation

server-only-label

SetVehicleSetup(number DragCoefficient = 0.3, number ThrottleInputRiseRate = 6, number ThrottleInputFallRate = 10, number BrakeInputRiseRate = 6, number BrakeInputFallRate = 10, number HandbrakeInputRiseRate = 12, number HandbrakeInputFallRate = 12, number SteeringInputRiseRate = 2.5, number SteeringInputFallRate = 5)

Configures the Vehicle General Settings. Check the page bottom to see each property explanation

server-only-label

SetTransmissionSetup(boolean bAutomaticTransmission = true, number GearSwitchTime = 0.5, number GearAutoBoxLatency = 2, number FinalRatio = 4, number ClutchStrength = 10)

Configures the Vehicle Transmission. Check the page bottom to see each property explanation

server-only-label

SetWheel(number Index (0-3), string BoneName, number ShapeRadius = 30, number ShapeWidth = 10, number SteerAngle = 70, number Mass = 20, number DampingRate = 0.25, number LatStiffMaxLoad = 2, number LatStiffValue = 17, number LongStiffValue = 1000, number SuspensionForceOffset = 0, number SuspensionMaxRaise = 10, number SuspensionMaxDrop = 10, number SuspensionNaturalFrequency = 7, number SuspensionDampingRatio = 1, number MaxBrakeTorque = 1500, number MaxHandbrakeTorque = 3000, boolean bAffectedByHandbrake = true, Vector Offset = Vector(0, 0, 0))

Configures a Vehicle Wheel. Check the page bottom to see each property explanation

server-only-label

SetDoor(number SeatIndex, Vector OffsetLocation, Vector SeatLocation, Rotator SeatRotation, number TriggerRadius, number LeaveLateralOffset)

Adds a Door at OffsetLocation from root which will pose the Character at SeatLocation with SeatRotation rotation. LeaveLateralOffset is where the Character will be ejected when leaving it (e.g. -150 for left door or 150 for right door)

server-only-label

SetSteeringWheelSetup(Vector Location, number Radius)

Configures where the Steering Wheel is located, so Characters can grab it procedurally properly

server-only-label

SetHeadlightsSetup(Vector Location, Color Color = Color(1, 0.86, 0.5))

Configures the Headlights Offset and Color.

string

GetAssetName()

Gets the Asset name

Character

GetPassenger(number Seat)

Gets all passengers. Returns nil if Seat is invalid or empty.

Character[]

GetPassengers()

Gets all passengers

Functions (Inherited from Actor)

Returns

Name

Description

server-only-label

AddImpulse(Vector Force)

Applies a Force in world coordinate on this Actor (the force is applied on Client side, by the (in most of cases) the closest player of this object)

server-only-label

AttachTo(Actor Other, string BoneName, Vector RelativeLocation, Rotator RelativeRotation)

Attaches this Actor to any other Actor with a Relative Offset/Rotation

server-only-label

Destroy()

Destroys this Actor

server-only-label

SetCollision(number CollisionType)

Sets the actor’s collision (0 - Normal, 1 - Static Only, 2 - No Collision)

server-only-label

SetGravityEnabled(boolean NewGravity)

Sets the actor’s gravity enabled

client-only-label

SetHighlightEnabled(boolean Enabled)

Sets if this Actors is Highlighting

server-only-label

SetInitialLocation(Vector NewInitialLocation)

Sets the initial location

server-only-label

SetLocation(Vector NewLocation)

Sets the actor’s location in the game world

server-only-label

SetRotation(Rotator NewRotation)

Sets the actor’s rotation in the game world

server-only-label

SetScale(Vector Scale)

Sets the actor’s scale

server-only-label

SetTintColor(Color NewTintColor)

Sets the tint color, for completely paint an object, multiply the color by 10 or 100

SetValue(string Key, any Value)

Sets a value in this entity, which can be accessed by any package (local only)

TranslateTo(Vector Location, number Speed)

Smoothly moves this actor to a Location with a certain Speed

RotateTo(Rotator Rotation, number Speed)

Smoothly rotates this actor to a Rotation with a certain Speed

boolean

IsGravityEnabled()

Gets the actor’s gravity enabled

boolean

IsValid()

Returns if this is Valid

number

GetCollision()

Gets the current actor’s collision

number

GetID()

Gets the network ID of this entity (same in both client and server)

Vector

GetLocation()

Get the actor’s position in the game world

server-only-label

Vector

GetInitialLocation()

Gets the initial location

Rotator

GetRotation()

Gets the actor’s rotation in the game world

Vector

GetScale()

Gets the actor’s scale

Color

GetTintColor()

Gets the Tint Color

string

GetType()

Returns the type of this Actor

any

GetValue(string Key)

Gets a value given a key

client-only-label

Vector

GetVelocity()

Returns the current actor Velocity

Events

Name

Arguments

Description

Horn

Vehicle self, boolean IsHonking

When Vehicle honks

Hit

Vehicle self, number Intensity

When Vehicle hits something

Events (Inherited from Actor)

Name

Arguments

Description

Destroy

Entity actor

Triggered when an Entity is Destroyed

Spawn

Entity actor

Triggered when an Entity is Spawned/Created

Parameters Detailed

Parameter Name

Description

number DifferentialType

0 - LimitedSlip_4W, 1 - LimitedSlip_FrontDrive, 2 - LimitedSlip_RearDrive, 3 - Open_4W, 4 - Open_FrontDrive, 5 - Open_RearDrive

number FrontRearSplit

Ratio of torque split between front and rear (>0.5 means more to front, <0.5 means more to rear, works only with 4W type)

number FrontLeftRightSplit

Ratio of torque split between front-left and front-right (>0.5 means more to front-left, <0.5 means more to front-right, works only with 4W and LimitedSlip_FrontDrive)

number RearLeftRightSplit

Ratio of torque split between rear-left and rear-right (>0.5 means more to rear-left, <0.5 means more to rear-right, works only with 4W and LimitedSlip_RearDrive)

number CenterBias

Maximum allowed ratio of average front wheel rotation speed and rear wheel rotation speeds (range: 1..inf, works only with LimitedSlip_4W)

number FrontBias

Maximum allowed ratio of front-left and front-right wheel rotation speeds (range: 1..inf, works only with LimitedSlip_4W, LimitedSlip_FrontDrive)

number RearBias

Maximum allowed ratio of rear-left and rear-right wheel rotation speeds (range: 1..inf, works only with LimitedSlip_4W, LimitedSlip_FrontDrive)

number MaxRPM

Maximum revolutions per minute of the engine

number MOI

Moment of inertia of the engine around the axis of rotation (Kgm^2)

number DampingRateFullThrottle

Damping rate of engine when full throttle is applied (Kgm^2/s)

number DampingRateZeroThrottle ClutchEngaged

Damping rate of engine in at zero throttle when the clutch is engaged (Kgm^2/s)

number DampingRateZeroThrottle ClutchDisengaged

Damping rate of engine in at zero throttle when the clutch is disengaged (in neutral gear) (Kgm^2/s)

number DragCoefficient

DragCoefficient of the vehicle chassis

number …InputRiseRate

Rate at which the input value rises

number …InputFallRate

Rate at which the input value falls

number GearSwitchTime

Time it takes to switch gears (seconds)

number GearAutoBoxLatency

Minimum time it takes the automatic transmission to initiate a gear change (seconds)

number FinalRatio

The final gear ratio multiplies the transmission gear ratios

number ClutchStrength

Strength of clutch (Kgm^2/s)

number ShapeRadius

Radius of the wheel

number ShapeWidth

Width of the wheel

number SteerAngle

Steer angle in degrees for this wheel

number Mass

Mass of this wheel

number DampingRate

Damping rate for this wheel (Kgm^2/s)

number LatStiffMaxLoad

Max normalized tire load at which the tire can deliver no more lateral stiffness no matter how much extra load is applied to the tire

number LatStiffValue

How much lateral stiffness to have given lateral slip

number LongStiffValue

How much longitudinal stiffness to have given longitudinal slip

number SuspensionForceOffset

Vertical offset from where suspension forces are applied (along Z-axis)

number SuspensionMaxRaise

How far the wheel can go above the resting position

number SuspensionMaxDrop

How far the wheel can drop below the resting position

number SuspensionNaturalFrequency

Oscillation frequency of suspension. Standard cars have values between 5 and 10

number SuspensionDampingRatio

The rate at which energy is dissipated from the spring. Standard cars have values between 0.8 and 1.2. Values < 1 are more sluggish, values > 1 or more twitchy

number MaxBrakeTorque

Max brake torque for this wheel (Nm)

number MaxHandbrakeTorque

Max handbrake brake torque for this wheel (Nm). A handbrake should have a stronger brake torque than the brake. This will be ignored for wheels that are not affected by the handbrake

Vector Offset

If BoneName is specified, offset the wheel from the bone’s location. Otherwise this offsets the wheel from the vehicle’s origin