Drive

The drive ability allows the character to drive any vehicle that implements the IDriveSource interface. This ability does not actually move the vehicle. This ability will move the character to the driving location and then allow the vehicle to have control over the input.

Setup

  1. Select the + button in the ability list under the “Abilities” foldout of the Ultimate Character Locomotion component.
  2. Add the Drive ability. The Drive ability should be positioned toward the top of the ability list.
  3. Add a component to the vehicle that implements the IDriveSource interface. In the demo scene this component is the SkyCar component. The IDriveSource implementation is also included within each vehicle integration.
  4. Add the Move Towards Location indicating where the character can enter or exit the vehicle.
  5. Set theĀ Driver Location on the IDriveSource component. This is the location that the character should be positioned when the character is driving the vehicle.
  6. Add the Smoothed Rigidbody component to the vehicle if the vehicle is a physics based vehicle and Ultimate Character Controller Camera Controller is used while driving. This will ensure the vehicle updates at the same rate as the character controller.

Drive Source Interface

The IDriveSource interface allows any vehicle able to be driven by the Drive ability. This interface includes information about the vehicle such as the GameObject, Transform, and the Transform that the character should be positioned to when they are driving the vehicle.

The AnimatorID property of the IDriveSource interface should return a unique animator value for that vehicle. A single Drive ability can be used for any number of vehicles, and the Animator can determine which drive animation to play based on the AnimatorID from the IDriveSource. The drive animation state will be the added onto the current vehicle’s Animator ID.

The IDriveSource contains methods that indicate when the character started to enter or exit the vehicle, as well as when the character completed the vehicle entrance or exit. In the demo scene the vehicle is enabled after the character has entered vehicle, and it is disabled when the character starts to exit the vehicle.

In the demo project, the SkyCar script is a simple example of how to implement the IDriveSource interface.

Animator ID

As mentioned in the previous section, a single Drive ability can be used for any number of vehicles. The vehicle AnimatorID value should be in an increment of 10, such as 0, 10, 20, 30, … 110, 120, … 1500, 1510, etc. This will allow the character’s Animator to determine which vehicle the character entered and what animation state they should be in. The following are valid animation states:

  • Enter: The character is entering the vehicle.
  • Drive: The character is driving the vehicle.
  • Exit: The character is exiting the vehicle.

Enter has a value of 0, Drive has a value of 1, and Exit has a value of 2. This value is added to the vehicle’s AnimatorID. As an example, if your vehicle has an AnimatorID value of 70, when the character is entering the vehicle the character’s AbilityIntData Animator parameter will have a value of 70 (70 + 0). When the character is driving the AbilityIntData will be 71 (70 + 1), and when the character is exiting the AbilityIntData value will be 72 (70 + 2).

Inspected Fields

Teleport Enter Exit

Should the character teleport for the enter and exit animations?

Can Aim

Can the Drive ability aim?

Move Speed

The speed at which the character moves towards seat position.

Rotation Speed

The speed at which the character rotates towards seat position.

Disable Mesh Renderers

Should the SkinnedMeshRenderer be disabled when the character enters the vehicle?