Vehicles

The Spatial Creator Toolkit provides a built-in, customizable vehicle system that allows you to create vehicles from custom Unity assets.

Input

For best practice, Spatial provides built in way to handle vehicle input.

Vehicle based input can be started by calling IInputService.StartVehicleInputCapture which has a parameter of type IVehicleInputActionsListener to receive callbacks for steer, throttle, reverse, and two customizable actions, depending on the flags passed in.

Each control is mapped to the following:

ControlsWebMobileVR
Steer 1DA/DOn Screen JoystickLeft Hand Joystick
Steer 2DW/A/S/DOn Screen JoystickLeft Hand Joystick
ThrottleW (1D Steering) / E (2D Steering)On Screen ButtonRight Hand Trigger
ReverseS (1D Steering) / Q (2D Steering)On Screen ButtonLeft Hand Trigger
Primary ActionSpaceOn Screen Button (using primary sprite set)Right Hand South Button
Secondary ActionShiftOn Screen Button (using secondary sprite set)Right Hand Grip
ExitFN\A (Use custom UI if needed)Right Hand North Button

Vehicle input capture can be released by calling IInputService.ReleaseInputCapture, passing in the reference to the same IVehicleInputActionsListener object used in the call to StartVehicleInputCapture.

Additionally, the vehicle input capture will be released if another input source begins its capture (with StartAvatarInputCapture, StartVehicleInputCapture, or StartCompleteCustomInputCapture).

Seat

Upon starting vehicle input capture, you can use IAvatar.Sit to sit the player's avatar down in the vehicle, attaching them to the Transform passed in.

Camera

Spatial provides a built in vehicle camera controller which can be used by calling ICameraService.SetTargetOverride, passing in SpatialCameraMode.Vehicle as the cameraMode.

Physics

Spatial provides and recommends you use the Vehicles layer. This layer has a preset configuration for Spatial's internal layers, but you can still change the settings for your space to determine how they collide with other Vehicles, Avatars, and your other custom layers (see Managing Collisions).