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:
Controls | Web | Mobile | VR |
---|---|---|---|
Steer 1D | A/D | On Screen Joystick | Left Hand Joystick |
Steer 2D | W/A/S/D | On Screen Joystick | Left Hand Joystick |
Throttle | W (1D Steering) / E (2D Steering) | On Screen Button | Right Hand Trigger |
Reverse | S (1D Steering) / Q (2D Steering) | On Screen Button | Left Hand Trigger |
Primary Action | Space | On Screen Button (using primary sprite set) | Right Hand South Button |
Secondary Action | Shift | On Screen Button (using secondary sprite set) | Right Hand Grip |
Exit | F | N\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).