Using an Existing Unity Project
Samples & Examples
Core Concepts & Glossary
Unity Package Types
Spaces & Space Templates
Custom Avatar Animations
Custom Prefab Objects
Quests and Rewards
Sync and Multiplayer
Supported Features and Limitations
Publishing to Spatial
Finding Published Packages
Help and Community
If you are new to the Creator Toolkit, make sure to check out following page to get your Unity editor setup!
This guide will show you how to set up a drivable vehicle that can be used in Spatial. This is to be used in conjunction with the Custom Prefab Object package type, which you can reference in the package configuration.
Importing a Vehicle Model & Requirements
- Import your vehicle model as an FBX file or .UnityPackage into your Unity project
- Currently supported: Grounded, 4 wheeled vehicles
- Each wheel needs to be a separate mesh/object within the model
Setting Up Your Vehicle (Grounded, 4-wheeled)
- Change the Layer of your vehicle to Vehicles
- Add Rigidbody component to the top level of your vehicle’s hierarchy
- Make sure to add the Mass of your vehicle (in KG), as well as the Drag and Angular Drag values.
- Leave Interpolate and Collision Detection as default
- Place an empty GameObject for the driver seat position, and move it to the location where the driver will be seated (NOTE: do not add it as a Seat Hotspot)
- Make sure it’s a child object of the vehicle
- Add a Mesh or Box Collider to the vehicle’s body
- Add a Center of Mass
- Create an empty Game Object, rename it “Center of Mass”
- Move the empty object to the approximate position of the Center of Mass of the vehicle
- Add Wheel Colliders for each wheel (make sure you have a rigidbody on your vehicle first
- Create a new empty Game Object called “Wheel Colliders” to place all the wheel colliders into
- With Wheel Colliders, create a collider for each wheel
- Create an empty Game Object
- Add the Wheel Collider component to the Game Object
- Give the colliders a consistent naming convention - for example “FR - Collider” for the Front Right wheel.
- Move the collider so it’s perfectly centered on the wheel
- Adjust the radius of the collider so it’s just visible around the wheel
- Add 2 Interactable components (no modifications or events for these Interactables needed)
Make sure to set the proper values of your Wheel Colliders’ properties specific to your vehicle. Learn more about Unity’s Wheel Collider Component here.
Ensure the wheel colliders and wheel meshes are facing the same orientation (Z+ forward orientation).
- StartInteractable - this will be used to have an avatar enter and take control of a vehicle.
- StopInteractable - to exit the vehicle and return control back to the avatar.
- Ensure the StopInteractable component is disabled by default
- To the top level vehicle object, add a Variables component
- Open the Vehicle sample provided in the Starter Template, and copy it’s Variables component as shown below
- Paste the Component values back in the Variables component of your vehicle
- Driver Seat hotspot
- WheelColliders (in order: Front Left, Front Right, Rear Left, Rear Right) - rear wheels must be last two in the list
- Center of Mass
- CameraTarget - On web and mobile, the camera will focus on this point when you enter the vehicle.
- Wheel meshes (allWheelVisuals) - must be in same order as WheelColliders
- maxDrive (Newton-Meters) - the maximum torque of the vehicle
- brakeForce (Newton-Meters) - the maximum brake force of the vehicle
- maxSteer - maximum angle that wheels turn (degrees)
- Open the sample Vehicle, and under it’s Script Machine click Edit Graph
- Ctrl/Cmd + A to select all the nodes, then Ctrl/Cmd+C to copy them
- Back on your Vehicle’s Script Machine, click new and save your Script. Then Edit Graph.
- Cmd/Ctrl + V to paste all the nodes
- Check Sync Transform
- Under Synced Variables, enable the following variables to be Synced
Vehicle Sample - Golf Cart
Introducing our sleek and stylish golf cart, perfect for developers who want to go for a test drive around Spatial in style. This little beauty will have you feeling like you're cruising down the fairway, even if you're just making laps around the parking lot. So hop on in, hit the gas pedal (or the brake if you're feeling cautious), and enjoy the ride. Just don't forget to yell "fore!" before taking any sharp turns!
Click below to download the sample from the Samples page, bring it into your project and review how to properly set up your own drivable vehicle!
Samples & Examples