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
Properties | Access | Description |
---|---|---|
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 |
FinalSteer | get | Returns the steer value similar to |
FinalThrottle | get | Returns the throttle value similar to |
FinalBrake | get | Returns the brake value similar to |
IsGrounded | get | Returns true if the vehicle is grounded. |
WheelHit | get | Return ground hit info if |
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 |
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
.
Override Methods | Description |
---|---|
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 |
FixedUpdate | Called each physx update before Update. |
Update | Called on each frame updating vehicle logic and controls. |
Methods | Description |
---|---|
AddForwardAcceleration(float accelerationForce) | Add forward acceleration applying a force to the |
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 |
VehicleGizmos Class Functions |
---|
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