How to enter and exit from a vehicle

On this page, you will learn how to setup the enter-exit vehicle system.

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.

PropertyDescription

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 Vehicle if is driving.

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 Vehicle. Can't be less than 0.1.

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 Layer property.

-> 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 AutoCheck true. Can't be less than 0.1 to avoid performance issues.

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.

How vehicle detection works ?

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.

Characters without driver animations

For simple games you can disable the character instead of use complex animations and IK system.

Simple Character Driver Animation

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.

Advanced Character Driver Animations with IK

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.

Standard IK Settings

Inverse Kinematics Target PositionsDescription

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 ParametersDescription

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)

Last updated