Road Tool
Curves (Mesh Deformation):
The rail guards in the scene use a Cinemachine Smooth Path to generate and deform objects with the Spline Tool script.
You can use this combination of tools for other set dressing elements that need to deform and follow a spline, such as fences or walls.
Use the Active Waypoints to control the shape of the spline.
Note: Gizmos enabled in the scene must be visible for you to be able to see Waypoints. You must also toggle the the Transform Gizmo “w”.
Adding and Removing Waypoints
The resolution of the Cinemachine path determines how smooth the path along which the deformation will take place will be:
- More points create a smoother the path.
- Fewer points create harder angles and rougher deformation.
Add or remove waypoints as necessary to control or extend the spline.
Create a Closed Loop
Use the Looped checkbox to create a closed loop instead of an open-ended spline.
Mesh Parameters
In the Spline Tool script, you can set a continuous Base Mesh, a Start, and an End Mesh to complete the spline.
Update the Spline in Real Time
If you need the tool to update the spline in real time, in the script component, select the Update Real Time.
Terrain Snapping
You can control terrain snapping. By default, the script uses the active layer (Terrain) to snap the smooth path and the objects to the terrain. To prevent snapping during mesh regeneration, deselect Terrain Snapping options.
Note: Terrain must exist under this layer for snapping to function correctly.
Transform Offsets and Randomization
Options in the Parameters section let you control transform offset values and randomization.
No offsets or randomization were used in the template.
Curves (Road Tool)
The road in the scene also uses a Cinemachine Smooth Path to generate the base mesh and the accompanying objects that are scattered along it.
Use a Custom Shape for Base Geometry
Inside the Road Tool script, the Cinemachine Smooth Path sweeps a custom shape along the curve to generate the base geometry for the road.
You can also create and use other custom shapes.
To make a custom shape, create a new shape scriptable object and assign 2D local shape vertices for it. The Tool handles the extrusion and and the number of slices/segments you define in the parameters.
Road Segments Options
The Road Segments option controls the smoothness and density of triangles for the final road base mesh.
- Use more road segments to improve the smoothness and accuracy of the spline resolution.
- Use the Width parameter to define the width of a lane. In this example, we use the parameter to define half of the road (in meters). We define the full width of the road as RoadWidth*2.
- To control the shape of the spline, use the Translate gizmo to move the control points around.
Tuning the Spline
To fine tune and control the spline, add or remove spline points.
Regenerate the Mesh
To regenerate the mesh, use the Regenerate button under the Road Tool script.
Curves (Object Scattering)
The Templates section in the Road Tool script controls object scattering, placement, and randomization.
You can add as many objects as you need. To avoid tedious repetitions, convert any spawnable object types to prefabs before you spawn them in the Road Tool. This way, if you need to change the original asset prefab, the changes propagate to the other prefabs within the Road Tool.
Spawn Rule Types
You can choose from multiple rule types for spawning the objects along the curve. The rules control where objects can spawn.
Rule | Description |
---|---|
Spawn Along Curve | Spawns a given prefab at the control points of a curve. |
Spawn at Curvature | Spawns a prefab at the curvature of a spline define by a threshold. |
Curve Spawn at Optimal Position | Spawns a prefab at the start of a curve. |
Curve Random Spawn | Spawns a prefab at random positions along the spline |
Generate Mesh Along Curve | Sweeps a defined shape along the spline to generate a mesh. |
Spawn at Position | Between 0 and 1 (start/end) to determine the exact position for an object to spawn. |
Spawn Rule Parameters
Customizing the spawning rule parameters helps you find the best placement for any prefab in the template list.
Regenerate
For each type of prefab in the template, you have the option to disable regeneration. Disabling regeneration prevents the system from randomizing the seed after regenerating the road each time when the prefab is already in the correct location.
Placement Along Curve
The Placement Along Curve section controls the distance from the center of the road at which the system spawns the object. It also controls the minimum spacing between prefabs along the spline.
Toggles
Select from the following toggles:
Toggle | Description |
---|---|
Orient with Curve | Select to permit the system orient objects with the curve. |
Snap to Terrain | Select to permit the system snap objects to the terrain. (Only functions if the terrain is located under the correct Terrain layer.) |
Deform with Curve | Select if you have objects that must both follow the spline and deform along the curve. You can also specify the Deformation Axis (default Z axis). |
Offsets
The Offsets section of the script lets you specify an offset value on top of the original spawn transform. You can precisely specify the translation, rotation, and scale of a template prefab.
Randomization
The Randomization section of the script lets specify the randomization per instance of the template prefab, on top of the original spawn location and any transforms.
You can increase or decrease the Seed number.
Prefabs and Variations
The Prefabs and Variations section lets you assign the prefab(s) that you want to spawn.
You can specify 1 or more prefabs:
- If you specify only 1 prefab, the system spawns only that prefab.
- If you specify 2 or more prefabs, the system randomly selects one of the prefabs in your list and places it along the road. This is useful if you want additional randomization.
Debugging
The Debugging section lets you toggle Gizmos so that you can see all the gizmos related to the Road Tool.
When you select Show Gizmos, you can see every control point on the curve and the orientation of each. This is helpful when you need to place procedural objects with the template parameters on the Road Tool.
Important: Make sure that Show Gizmos is also selected in the viewport.