Getting Started
Package Types
Scene Setup
Custom Collision, Layers, and Tags
Key Differences from Standard Unity3D development
Economy
C# Scripting
Sync and Multiplayer
<aside> <img src="/icons/star_green.svg" alt="/icons/star_green.svg" width="40px" /> If you are new to the Creator Toolkit, make sure to check out following page to get your Unity editor setup!
</aside>
<aside> <img src="/icons/book_gray.svg" alt="/icons/book_gray.svg" width="40px" /> 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.
</aside>
Change the Layer of your vehicle to Vehicles
Add Rigidbody component to the top level of your vehicle’s hierarchy
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)
Add a Mesh or Box Collider to the vehicle’s body
Add a Center of Mass
Add Wheel Colliders for each wheel (make sure you have a rigidbody on your vehicle first
<aside> <img src="/icons/car_yellow.svg" alt="/icons/car_yellow.svg" width="40px" /> 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.
</aside>
<aside> <img src="/icons/warning_gray.svg" alt="/icons/warning_gray.svg" width="40px" /> Ensure the wheel colliders and wheel meshes are facing the same orientation (Z+ forward orientation).
</aside>
Wheel mesh (blue outline), with the Wheel Collider (green line) visible around the tire. Both have the Z+ (blue arrow) pointing towards the front of the vehicle.
Add 2 Interactable components (no modifications or events for these Interactables needed)
Add a Variables component
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
Assign your vehicle’s assets to the relevant Variables
Driver Seat hotspot
StartInteractable
StopInteractable
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
Set values for other Variables
Add a Script Machine component to your vehicle to the top level of your vehicle
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
Add a Synced Object Component
If publishing as an individual object that can be accessed from your Content menu, add the Prefab Object Component
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!
<aside> 👉 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!
</aside>
← Previous
Next →