Gameplay / AdvancedVehicle
AdvancedVehicle Class
Four-wheel vehicle
Four wheel vehicles refer to vehicles simulating four wheels, such as cars, trucks, etc. They are designed to move, accelerate and turn freely in the game, giving Player a real driving experience.
Precautions
Important Notes
- Before the effective owner is set, the vehicle will not carry out physical simulation, and may encounter suspended phenomena.
- The vehicle is control by the Player client specified during the set owner. If you want to set the position of the vehicle, setting the position only on the server side is invalid and needs to be modified together with the main control end.
- Attention should be paid to the number of vehicles controlled simultaneously by the same client. If the number is too large, it will affect the synchronization of the vehicles. Suggest within 5.
Usage example: Dynamically create vehicles through scripts and bind control logic. Create a script named 'VehicleExample', place it in the object bar, open the script, enter the following code to save, and run the game. Press the Q key to create the vehicle, and when it reaches the trigger range, it will automatically get on board. WASD will drive it, and press the F key to get off. The code is as follows:
Hierarchy
↳
AdvancedVehicle
Table of contents
Properties
vehicleLog: any |
---|
click
Properties
onBeforeDestroyDelegate: MulticastDelegate <() => void > other |
---|
Event callback before object destruction |
onCustomPropertyChange: Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> other |
Monitor custom attribute synchronization events |
onDestroyDelegate: MulticastDelegate <() => void > other |
Event callback after object destruction |
onPropertyChange: Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> |
Monitor system replicated events |
Accessors
acceleration(): number other |
---|
Get acceleration. |
brakingTorque(): number other |
Obtain the brake torque. Unit: N * m |
currentGearLevel(): number other |
Get the current gear level. |
driveMode(): VehicleDriveMode4WNew other |
Get the vehicle drive mode. |
friction(): number other |
Obtain the friction coefficient of vehicle. |
handbrakeInputEnable(useHandbrake : boolean ): void other |
Whether to apply handbrake, true - apply brake, false - cancel brake. |
mass(): number other |
Obtain quality. |
maxEngineRPM(): number other |
Obtain the maximum engine speed. Unit: revolutions per minute (r/min) |
maxGearLevel(): number other |
Obtain the maximum gear level. If the return value is 4, it indicates the presence of [-1, 0, 1, 2, 3, 4] gears. |
owner(): Player other |
Obtain the driver of the vehicle. |
simulatePhysics(shouldSimulate : boolean ): void other |
Whether to enable physical simulation calculation for four-wheel vehicles needs to be called on the client side. |
steeringInput(newInput : number ): void other |
Control the left/right steering of vehicle, set the steering amplitude, and the value range is [-1,1]. If it is greater than 0, turn right, and if it is less than 0, turn left. |
throttleInput(newInput : number ): void other |
Control the forward/backward movement of the vehicle, set the throttle size within the range of [-1,1], accelerate when it is greater than 0, and decelerate when it is less than 0. |
velocity(): number other |
Obtain the current driving speed in meters per second (m/s). |
wheelNum(): number other |
Obtain the number of wheels. |
click
Accessors
actorFlagValue(): number other |
---|
Get object tags |
actorLevel(): number other |
Obtain Actor Level |
assetId(): string other |
Retrieve the UID of the resource currently being used by the object |
gameObjectId(): string other |
Get the unique identification of an object (a string that uniquely identifies an object). |
isDestroyed(): boolean other |
Has the current object been destroyed |
isReady(): boolean other |
Current object status |
localTransform(): Transform other |
Local transformation of the current object |
name(): string other |
Return the current object name |
netStatus(): NetStatus other |
Get the current object synchronization status |
parent(): GameObject other |
Retrieve the current parent object |
tag(): string other |
Get the tag of the current object |
worldTransform(): Transform other |
Current object world transformation |
Methods
gearDown(): void other |
---|
Lower the gear and switch immediately. |
gearUp(): void other |
Upgrade one level and switch immediately. |
getGearData(gearLevel : number ): VehicleGearDataNew other |
Retrieve the specified gear attribute |
getWheelMaxSteerAngle(wheelId : number ): number other |
Obtain the maximum steering angle of the wheels, in degrees (°). |
getWheelModel(wheelId : number ): string other |
Retrieve the tire binding object. |
getWheelRadius(wheelId : number ): number other |
Obtain the wheel radius in centimeters (cm). |
onDestroy(): void other |
Destruction |
setCullDistance(inCullDistance : number ): void other |
Objects beyond this distance between players will be cropped, and the final cropping distance will depend on the image quality level; When this property is modified to ≤ 0, the cropping distance will be automatically adjusted according to the object size (CullDistanceVolume function will be automatically enabled) |
setWheelRadius(wheelId : number , Radius : number ): void other |
Set the wheel radius in centimeters (cm). |
click
Methods
addComponent<T : extends Script <T >>(constructor : (...args : unknown []) => T : extends Script <T >, bInReplicates? : boolean ): T : extends Script <T > other |
---|
Add a script component |
asyncGetChildByName(name : string ): Promise <GameObject > other |
Asynchronous search for sub objects based on their names |
asyncReady(): Promise <GameObject > other |
Return after the object is ready |
clone(gameObjectInfo? : GameObjectInfo ): GameObject other |
Copy Objects |
destroy(): void other |
delete object |
getBoundingBox(nonColliding? : boolean , includeFromChild? : boolean , outer? : Vector ): Vector other |
Get the size of the object's bounding box |
getBounds(onlyCollidingComponents : boolean , originOuter : Vector , boxExtentOuter : Vector , includeFromChild? : boolean ): void other |
Obtain object boundaries |
getChildByGameObjectId(gameObjectId : string ): GameObject other |
Search for sub objects based on gameObjectid |
getChildByName(name : string ): GameObject other |
Search for sub objects by name |
getChildByPath(path : string ): GameObject other |
Find sub objects according to path |
getChildren(): GameObject [] other |
Obtain sub objects |
getChildrenBoundingBoxCenter(outer? : Vector ): Vector other |
Get the center point of all child objects' bounding box (not including the parent object, if the parent object is unavailable, return [0,0,0]) |
getChildrenByName(name : string ): GameObject [] other |
Search for all sub objects by name |
getComponent<T : extends Script <T >>(constructor? : (...args : unknown []) => T : extends Script <T >): T : extends Script <T > other |
Get the component of the specified type |
getComponentPropertys<T : extends Script <T >>(constructor : (...args : unknown []) => T : extends Script <T >): Map <string , IPropertyOptions > other |
Get property of script component |
getComponents<T : extends Script <T >>(constructor? : (...args : unknown []) => T : extends Script <T >): T : extends Script <T >[] other |
Get all component of the specified type |
getCustomProperties(): string [] other |
Get all customize property |
getCustomProperty<T : extends CustomPropertyType >(propertyName : string ): T : extends CustomPropertyType other |
Get customize property |
getCustomPropertyChangeDelegate(property ): Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> other |
Event proxy triggered when a given object property is modified |
getPropertyChangeDelegate(property ): Readonly <MulticastDelegate <(path : string , value : unknown , oldValue : unknown ) => void >> other |
Event proxy triggered when a given object property is modified |
getVisibility(): boolean other |
Obtain whether the object is displayed |
isPrefabActor(): boolean other |
Return whether the current object is a prefabricated body |
moveBy(velocity : Vector , isLocal? : boolean ): void other |
Smoothly move an object over time according to a given velocity vector |
moveTo(targetPosition : Vector , time : number , isLocal? : boolean , onComplete? : () => void ): void other |
Smoothly move from the current position to the target position within the specified time |
rotateBy(rotation : Quaternion Rotation , multiplier : number , isLocal? : boolean ): void other |
Rotate the object smoothly over time according to the given rotation amount |
rotateTo(targetRotation : Quaternion Rotation , time : number , isLocal? : boolean , onComplete? : () => void ): void other |
Smoothly changes from the current rotation to the target rotation within the specified time |
scaleBy(scale : Vector , isLocal? : boolean ): void other |
Smoothly scale objects over time using a given scaling vector per second |
scaleTo(targetScale : Vector , time : number , isLocal? : boolean , onComplete? : () => void ): void other |
Smoothly changes from the current scale to the target scale within the specified time |
setAbsolute(absolutePosition? : boolean , absoluteRotation? : boolean , absoluteScale? : boolean ): void other |
Set whether the object localTransform is relative to the parent object or the world |
setCustomProperty(propertyName : string , value : undefined CustomPropertyType ): void other |
Set custom attributes |
setVisibility(status : boolean PropertyStatus , propagateToChildren? : boolean ): void other |
Set whether the object is displayed |
stopMove(): void other |
Interrupt further movement of moveTo() and moveBy() |
stopRotate(): void other |
Interrupt further rotation from rotateTo() or rotateBy() |
stopScale(): void other |
Interrupt further scale from ScaleTo() or ScaleBy() |
asyncFindGameObjectById(gameObjectId : string ): Promise <GameObject > other |
Asynchronous search for GameObject through gameObjectid |
asyncGetGameObjectByPath(path : string ): Promise <GameObject > other |
Asynchronously find objects through path |
asyncSpawn<T : extends GameObject <T >>(assetId : string , gameObjectInfo? : GameObjectInfo ): Promise <T : extends GameObject <T >> other |
Asynchronous construction of an object |
bulkPivotTo(gameObjects : GameObject [], transforms : Transform []): void other |
Batch set position |
findGameObjectById(gameObjectId : string ): GameObject other |
Search for objects through gameObjectid |
findGameObjectByName(name : string ): GameObject other |
Search for objects by name |
findGameObjectsByName(name : string ): GameObject [] other |
Search for objects by name |
findGameObjectsByTag(tag : string ): GameObject [] other |
Get objects through customize tag |
getGameObjectByPath(path : string ): GameObject other |
Search for objects through paths |
spawn<T : extends GameObject <T >>(assetId : string , gameObjectInfo? : GameObjectInfo ): T : extends GameObject <T > other |
Construct an object |
Properties
vehicleLog
• Private
vehicleLog: any
------------------------------------------ Internal property/function------------------------------------------
Accessors
acceleration
• | • | ||||
---|---|---|---|---|---|
Get acceleration. Returns
| Set acceleration.
[0.01, 100] Parameters
|
brakingTorque
• | • | ||||
---|---|---|---|---|---|
Obtain the brake torque. Unit: N * m Vehicle braking torque refers to the torque applied to the vehicle braking system for deceleration or stopping vehicle motion. It is the torque generated by the braking system, applied to the wheels through brakes such as brake discs and brake pads, thereby reducing the rotational speed of the wheels. Returns
| Set the brake torque. Unit: N * m
[0, 1000000] Parameters
|
currentGearLevel
• | • | ||||
---|---|---|---|---|---|
Get the current gear level. Returns
| Set the current gear level.
[-1, Maximum gear set] Precautions
Parameters
|
driveMode
• | ||
---|---|---|
Get the vehicle drive mode. Returns
|
friction
• | • | ||||
---|---|---|---|---|---|
Obtain the friction coefficient of vehicle. Returns
| Set vehicle wheel friction coefficient
[0.01, 8] Parameters
|
handbrakeInputEnable
• | ||
---|---|---|
Whether to apply handbrake, true - apply brake, false - cancel brake. Precautions When the input value changes, call once. The input value will be maintained, and no continuous call is required. Parameters
|
mass
• | • | ||||
---|---|---|---|---|---|
Obtain quality. Returns
| Set the mass of vehicle in kilogram.
[0.01, 100000] Precautions
Parameters
|
maxEngineRPM
• | • | ||||
---|---|---|---|---|---|
Obtain the maximum engine speed. Unit: revolutions per minute (r/min) Returns
| Set the maximum engine speed. Unit: revolutions per minute (r/min)
[100, 5000000] Parameters
|
maxGearLevel
• | ||
---|---|---|
Obtain the maximum gear level. If the return value is 4, it indicates the presence of [-1, 0, 1, 2, 3, 4] gears. Precautions The maximum gear that can be switched to. To obtain the current gear, please use getCurrentGearLevel Returns
|
owner
• | • | ||||
---|---|---|---|---|---|
Obtain the driver of the vehicle. Returns
| Set the vehicle driver. Only the driver can operate the vehicle. Parameters
|
simulatePhysics
• | ||
---|---|---|
Whether to enable physical simulation calculation for four-wheel vehicles needs to be called on the client side. Precautions The four-wheel vehicle will only undergo physical simulation after the set owner is successful. At this time, closing the physical simulation will no longer drive the vehicle to move. Parameters
|
steeringInput
• | ||
---|---|---|
Control the left/right steering of vehicle, set the steering amplitude, and the value range is [-1,1]. If it is greater than 0, turn right, and if it is less than 0, turn left.
[-1, 1] Turn right when it is greater than 0, and turn left when it is less than 0. Precautions
Usage example: Control the vehicle with buttons and joysticks ts Parameters
|
throttleInput
• | ||
---|---|---|
Control the forward/backward movement of the vehicle, set the throttle size within the range of [-1,1], accelerate when it is greater than 0, and decelerate when it is less than 0.
[-1, 1] Accelerate when greater than 0, decelerate when less than 0. Precautions
Usage example: Control the vehicle with buttons and joysticks ts Parameters
|
velocity
• | ||
---|---|---|
Obtain the current driving speed in meters per second (m/s). Returns
|
wheelNum
• |
---|
Obtain the number of wheels. Returns |
number | Number of wheels |
---|
Methods
gearDown
• gearDown(): void
other
Lower the gear and switch immediately.
gearUp
• gearUp(): void
other
Upgrade one level and switch immediately.
getGearData
• getGearData(gearLevel
): VehicleGearDataNew
other
Retrieve the specified gear attribute
Parameters
gearLevel number | Specify gear level range: [0,1] type: floating point number |
---|
Returns
VehicleGearDataNew | Specify the gear attribute |
---|
Precautions
Pay attention to the range of input parameter values
getWheelMaxSteerAngle
• getWheelMaxSteerAngle(wheelId
): number
other
Obtain the maximum steering angle of the wheels, in degrees (°).
Parameters
wheelId number | Specify the wheel according to the serial number range: 0.1.2.3 four parameters type: integer |
---|
Returns
number | Specify the maximum steering angle of the specified wheel |
---|
Pay attention to the range of input parameter values. The current vehicle is a four-wheel vehicle, with [0, 1, 2, 3] corresponding to [left front, right front, left rear, right rear].
getWheelModel
• getWheelModel(wheelId
): string
other
Retrieve the tire binding object.
Parameters
wheelId number | Specify the wheel according to the serial number range: 0.1.2.3 four parameters type: integer |
---|
Returns
string | Specify the tire binding object UID |
---|
Pay attention to the range of input parameter values. The current vehicle is a four-wheel vehicle, with [0, 1, 2, 3] corresponding to [left front, right front, left rear, right rear].
getWheelRadius
• getWheelRadius(wheelId
): number
other
Obtain the wheel radius in centimeters (cm).
Parameters
wheelId number | Specify the wheel according to the serial number range: 0.1.2.3 four parameters type: integer |
---|
Returns
number | Specify wheel radius |
---|
Pay attention to the range of input parameter values. The current vehicle is a four-wheel vehicle, with [0, 1, 2, 3] corresponding to [left front, right front, left rear, right rear].
onDestroy
• Protected
onDestroy(): void
other
Destruction
setCullDistance
• setCullDistance(inCullDistance
): void
other
Objects beyond this distance between players will be cropped, and the final cropping distance will depend on the image quality level; When this property is modified to ≤ 0, the cropping distance will be automatically adjusted according to the object size (CullDistanceVolume function will be automatically enabled)
Parameters
inCullDistance number | Usage: cull distance range: recommended (2000, 4000) type: floating point |
---|
Precautions
The final cull distance will be related to the graphics quality level
setWheelRadius
• setWheelRadius(wheelId
, Radius
): void
other
Set the wheel radius in centimeters (cm).
Parameters
wheelId number | Specify the wheel according to the serial number range: 0.1.2.3 four parameters type: integer |
---|---|
Radius number | Specify wheel radius range: No restrictions, reasonable is sufficient Type: Floating point number |
Pay attention to the range of input parameter values. The current vehicle is a four-wheel vehicle, with [0, 1, 2, 3] corresponding to [left front, right front, left rear, right rear]. It only takes effect before boarding, and call this API after boarding has no effect.