Coding Custom Wheeled Vehicles
You can program custom wheeled vehicles easily in JU TPS
How to create a Custom Wheeled Vehicle script
Create a script that will contain the code of the vehicle.
Use this as example:
This code is an example how you can create your our wheeled vehicle, with engine, brake and steer.
All base system for wheeled vehicles are provided from Vehicle
class.
You must only set the vehicle controls, overriding Update
and pass the wheels to vehicle backend using the UpdateWheelsData
.
After setup this code to the vehicle and assigned all wheels, you will have a full controllable vehicle.
Vehicle Coding Scripting Reference
Steer
get, set
The steer input to control the vehicle move direction. A value between -1 to 1 where -1 is to turn to left, 0 to not turn and 1 is to move to right.
Throttle
get, set
The throttle input to control the vehicle engine acceleration. A value between -1 to 1 where -1 is to move to backward, 0 to be stoped and 1 to move to forward.
Brake
get, set
A value between 0 and 1 where 0 is without brake and 1 is full brake.
CanTurnToUpInAir
protected get, set
When true, the vehicle will turn when IsGrounded
is false to align the Up
with if RotateToUpInAirSpeed
is greater than 0.
FinalSteer
get
Returns the steer value similar to Steer
input but with smooth provided from DrivePadSmooth
.
FinalThrottle
get
Returns the throttle value similar to Throttle
input but with smooth provided from DrivePadSmooth
.
FinalBrake
get
Returns the brake value similar to Brake
input but with smooth provided from Throttle
.
IsGrounded
get
Returns true if the vehicle is grounded.
WheelHit
get
Return ground hit info if IsGrounded
is true.
LocalVelocity
get
Returns the relative vehicle velocity.
WheelsUpDirection
get
Returns the vehicle up based on the median direction of all wheels positions.
CurrentSteerVsSpeed
get
Returns the SteerVsSpeed
value relative to the current velocity. Used to improve the control on high speeds, decreasing the steer to make curves more smoothly.
RigidBody
get
The rigidbody body of this vehicle.
ForwardSpeed
get
Returns the vehicle forward speed.
You can override the base methods to create custom vehicle logic.
Don't forgot to call the base methods inside the override
.
OnValidate
Used only by the editor, called after change some property on the editor to validate variables.
Awake
Called when the scene load.
Start
Called when the game starts, after Awake
FixedUpdate
Called each physx update before Update.
Update
Called on each frame updating vehicle logic and controls.
AddForwardAcceleration(float accelerationForce)
Add forward acceleration applying a force to the Rigidbody
to forward.
SimulateAntiRollBar(float antiRollForce, WheelCollider LeftWheel, WheelCollider RightWheel)
Simulate car anti roll bar
SetVehicleCenterOfMass(Transform position)
Set vehicle center of mass
SimulateGroundAlignment(float alignmentSpeed)
Align vehicle to ground
Vector3 GetExitPosition()
Get character exit position
DrawVector3Position(Vector3 position, Transform Vehicle, string Label, Color color)
DrawVehicleInclination(Transform RotationParent, Transform RotationChild)
DrawRaycastHit(VehicleRaycastCheck rayCheck, Transform vehicle, Vector3 direction)
DrawOverturnCheck(VehicleOverturnCheck OverturnCheck, Transform Vehicle)
DrawOverlapBoxCheck(VehicleOverlapBoxCheck BoxCheck, Transform Vehicle)
DrawVehicleGroundCheck(VehicleGroundCheck GroundCheck, Transform Vehicle)
Last updated