How to enter and exit from a vehicle
On this page, you will learn how to setup the enter-exit vehicle system.
Last updated
On this page, you will learn how to setup the enter-exit vehicle system.
Last updated
Any vehicle can be controlled by the player, basically the entry system will disable the character controls and enable the vehicle control.
To drive a Vehice
the character must have the DriveVehicleSystem
, this component add the ability to find near vehicles and entry on it.
Property | Description |
---|---|
Start Vehicle | A default vehicle to start driving |
Enter Vehicles Enabled | If true, the character can enter and drive vehicles. |
Exit Vehicles Enabled | If true, the character can exit from the |
Disable Character On Enter | Disable the character after enter on the vehicle, usefull for vehicles that not have IK settings for drive animations. |
Delay To Re enable Action | The time to reactive enter vehicle action after start enter or exit of some |
Use Default Inputs | Use default player controls to enter and exit vehicles. |
Check Near Vehicles | Stores the properties that allow to find closest vehicles. |
-> Layer | The layer used to find the vehicles. |
-> Avoid Obstacles | Find vehicles only if there are not obstacles between the vehicle and the character, it's uses the |
-> Enter Vehicles Area Tag | Used to find only specifics colliders as trigger with this tag to be used as a area to enter on the vehicle. |
-> Check Range | The max distance to find vehicles. |
-> Auto Check | If true, the driver system will research vehicles on each X times. |
-> Auto Check Interval | Used to auto find near vehicles several times per second if is |
Max Vehicle Speed To Enter | Don't allow to enter on vehicles in movement. |
Max Vehicle Speed To Exit | Don't allow to exit from a vehicle on high speeds. |
Max Character Speed To Enter | Don't allow to character enter on a vehicle if the character is in movement. |
Ground Layer | The layer used to detect the ground to set the character position when exit from the current vehicle. |
Vehicles must have a child trigger with a specific tag and layer.
With this settings, the character will find the VehicleArea collider of the example vehicle if the character is nearest to the box. The search happen each 0.5 seconds. You can see the Layer
contains Default, Ignore Raycast
and Walls
. Only the Ignore Raycast
layer is necessary to find the vehicle but Default
and Walls
can be used as obstacles to avoid if AvoidObstacles
is true.
It's not recommended use AutoCheck
on all characters because it's can reduce the performance depending of the level complexity. Use auto check only on important characters like the player.
If you need to have enter/exit on many characters try:
Increase the AutoCheckInterval
example 1, 2 seconds...
Disable the AutoCheck
by distance.
Set AutoCheck
as false and call DriverVehicles.FindNearVehicles()
when necessary.
For simple games you can disable the character instead of use complex animations and IK system.
If you have a character animation that match with the vehicle model you can use the JUVehicleCharacterIK
to set the character position inside the vehicle.
You can use foot and hand IK on vehicles if you want, very useful to make wheel steer, motorcycle inclination animation or foot placements.
To use it, the character must have the DriverProceduralAnimation
component, it's is responsible by the IK system.
Furthermore, you need to have assigned all the IK target positions on the JUVehicleCharacterIK
of the vehicle and the IK weights configured.
Tip: if you see a prefab of a vehicle you will notice hand, foot, sphere or humanoid character gizmos. You can copy these GameObjects, paste them into your new vehicle, position them and assign them to the above parameters.
Inverse Kinematics Target Positions | Description |
---|---|
Character Location | Character body position in vehicle |
Left Hand Position IK | Left hand position and rotation in vehicle |
Right Hand Position IK | Right hand position and rotation in vehicle |
Left Foot Position IK | Left foot position and rotation in vehicle |
Right Foot Position IK | Right foot position and rotation in vehicle |
IK Animation Weights Parameters | Description |
---|---|
Frontal Lean Weight | Frontal Lean Motion Weight IK |
Side Lean Weight | Side lean Motion Weight IK |
Look At Direction Weight | Look At Motion Weight IK |
Hint Movement Weight | Hint Motion Weight IK |
Foot Placement | Foot placement in driving (Motorcycle or Bike for example) |