docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Road Tool

    • Curves (Mesh Deformation)
    • Curves (Road Tool)
    • Curves (Mesh Scattering)

    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”.

    alt_text

    alt_text

    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.

    alt_text

    Add or remove waypoints as necessary to control or extend the spline.

    alt_text

    Create a Closed Loop

    Use the Looped checkbox to create a closed loop instead of an open-ended spline.

    alt_text

    Mesh Parameters

    In the Spline Tool script, you can set a continuous Base Mesh, a Start, and an End Mesh to complete the spline.

    alt_text

    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.

    alt_text

    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.

    alt_text

    Note: Terrain must exist under this layer for snapping to function correctly.

    alt_text

    Transform Offsets and Randomization

    Options in the Parameters section let you control transform offset values and randomization.

    alt_text

    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.

    alt_text

    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.

    alt_text

    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.

    alt_text

    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.

    alt_text

    Tuning the Spline

    To fine tune and control the spline, add or remove spline points.

    alt_text

    Regenerate the Mesh

    To regenerate the mesh, use the Regenerate button under the Road Tool script.

    alt_text

    Curves (Object Scattering)

    The Templates section in the Road Tool script controls object scattering, placement, and randomization.

    alt_text

    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.

    alt_text

    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.

    alt_text

    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.

    alt_text

    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.

    alt_text

    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).

    alt_text

    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.

    alt_text

    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.

    alt_text

    Prefabs and Variations

    The Prefabs and Variations section lets you assign the prefab(s) that you want to spawn.

    alt_text

    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.

    alt_text

    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.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)