Skip to content

A getting started tutorial

Patrick W. Crawford edited this page Sep 23, 2024 · 6 revisions

Use this page to quickly get started with using the Godot Road Generator adodn.

Video demonstration

https://www.youtube.com/watch?v=aIRRMrj7ahI&feature=youtu.be

Step 1: Download and add to project

Download the latest release (dev may be unstable, main should match the latest release). Then, copy the addons/road-generator folder into your project. If you have any other addons installed, then your current addons folder will already exist.

The plugin is also available on in the Godot Asset Library, though updates take a little longer to reach there.

Step 2: Enable the plugin

  1. Go to the Project menu > Project Settings.
  2. Select the Plugins tab
  3. Enable the road-generator plugin

Step 3: Add a RoadManager

  1. In any 3D scene, open the add child node menu
  2. Search for "RoadManager"
  3. Add the node into your scene, in any spot

This node is responsible of keeping track of all the roads in the scene, and for propagating down settings such as mesh density. See RoadManager documentation for more details

Step 4: Add a RoadContainer

Before you can start creating roads, you need a "RoadContainer." You can do this in a few ways:

  • Using "add mode"
    1. Make sure the RoadManager is selected, so the Roads toolbar is visible atop the 3D viewport
    2. Enter the "Add Mode" by clicking the green + icon (similar to when working with built in 3d Paths)
    3. Now click anywhere in the scene, a RoadContainer will be automatically place in the same spot as the manager.
  • Using the 3d viewport toolbar's Roads dropdown: Add RoadContainer
  • Using the general built-in Add Node button, and searching for RoadContainer. If creating the road manually this way, just be sure it is placed as a child of the RoadManager, and not the child of another RoadContainer or any other Road-node

Be aware that a RoadContainer is a spatial, so you can rotate or translate the entire RoadContainer as one chunk. You are not recommended to scale RoadContainers or their children. Use the "Road Width" on individual RoadPoints if you want to change the physical size of Roads.

Step 5: Add your first RoadPoints

This is most easily done by using Add Mode mentioned in the step above. Make sure the RoadContainer created is selected, and then start clicking anywhere in your scene to start placing RoadPoints. Go onto the next step once you've added two RoadPoints.

Be aware that whilst in Add Mode, the placement of new RoadPoints takes precedent over 3D transform gizmos. If you want to adjust the position of any RoadPoint after placement, go back to Select mode (blue cursor).

Instead of using add mode, you can use the preset "2x2 road" from the Road dropdown menu in the 3D toolbar, or with one of the "Edge" RoadPoints selected, use the Inspector panel to "+ Prior/Next RoadPoint".

You should now have the following setup (note: you could also have the RoadManager as the scene root if you wanted):

- [scene root or other parent nodes]
  - RoadManager (RoadManager, road_manager.gd)
    - Road001 (RoadContainer, road_container.gd)
      - RP_001 (RoadPoint, road_point.gd)
      - RP_002 (RoadPoint, road_point.gd)

Step 6: Change the number of lanes

After selecting one of the RoadPoints, use the panel in the Inspector to change the number of lanes by pressing "+" or "-" on one side of the road or the other. Hold shift to affect all RoadPoints in the container instead of just this one. If you go back to Select mode, you can also adjust the number of lanes using the blue gimzo in the 3D viewport. Again, hold shift to affect the entire RoadContainer at once.

All RoadPoint settings on a single RoadPoint are specific to itself, and will be interpolated between two RoadPoints. This includes properties like road width and shoulder size. See the RoadPoint documentation for more information.

If you want to bring changes like shoulder and lane width from one RoadPoint to another, press the Copy Settings button when the source RoadPoint is selected. Then, either selected another RoadPoint and press Apply Settings, or hold shift and Apply Settings to the entire RoadContainer to force all RoadPoints to have the same configuration.

Step 7: Create a closed loop

Let's say you want to have a closed loop track for your road, with no intersections or anything like that.

  1. Create and place all the RoadPoints necessary, such that you are left with a gap for just one more RoadSegment
  2. Select either this first RoadPoint of this gap.
  3. With the Add Mode enabled, hover over the other RoadPoint. You should see a blue hinting line appear (if necessary, nudge your mouse over the road mesh coming out the other side this other RoadPoint)
  4. On click, this will connect the RoadPoints together

This connection tool in Add Mode also works to disconnect RoadPoints already connected to the currently selected RoadPoint. This is not to be confused with the Delete Mode, which is another mode used to dissolve a RoadPoint and connect its two neighbors together.

Step 8: Connect two different RoadContainers

A RoadPoint should only ever directly connect to another RoadPoint who is a child of the same RoadContainer. This is because RoadContainers could actually come from different saved scenes, for modularity and reuse.

Instead, the plugin uses other methods and mechanisms to create connections between two different RoadContainers.

  1. Press control-z or use the disconnection tool (in Add Mode) so that this road has 1+ open connection
  2. Select your current RoadContainer
  3. In the hierarchy viewer, right click and duplicate the whole RoadContainer
  4. Using the native 3D gizmo or transform panel, move/rotate this RoadContainer to the side a bit so it's not overlapping
    • Make sure to changed back to Select mode, in case you had Add mode on before. Otherwise, new clicks will just add new RoadPoints instead of transforming anything.
  5. With the blue Select tool enabled, click on one of the open RoadPoints on either RoadContainer
  6. Switch to Add Mode (green +), and hover your mouse over an open connection on the other RoadContainer
  7. Left click to confirm the connection. This will:
    • Add a new RoadPoint on the currently selected RoadContainer (and thus the gap will be bridged using the material and density specified by the selected RoadContainer), but at the exact position and orientation of the RoadPoint on the other container.
    • The export variable arrays of both RoadContainers have now been established to "point to each other" to those specific RoadPoints

Step 9: Move/adjust connected RoadContainers

Please be aware that there are some current limitations around connections between RoadContainers:

  • The connection between two RoadPoints is entirely virtual; you can still move one container or the other and their respective points freely, causing the connected RoadPoints to no longer overlap.
    • The plugin will at least warn you, though, when two edge-connected RoadPoints no longer overlap.
    • This warning will appear on the RoadContainer, and generally can be resolved by pressing Refresh Road with that Container selected.
  • RoadLanes (for AI) do not update their "next/prior lane" references between RoadContainers
  • Changes in one RoadPoint edge will not reflect on the other (e.g. if you reduce the number of lanes), and would result in a mismatched connection
    • See the example below on how to deal with this in practice, for now

These are all things which will be improved over time. But in the meantime, consider the following example to follow:

Scene hierarchy

- RoadManager
  - ContainerA
    - RP_1 # which is connected to RP_A of ContainerB
    - ...
  - ContainerB
    - RP_A # which is connected to RP_1 of ContainerA
    - RP_B # connected to RP_A in this container
    - ...

  1. Go ahead and transform the RoadContainer / RoadPoint as desired
    • For this analogy, assume that we just modified ContainerA or RP_1's position
    • This would result in the RoadPoints no longer being lined up at the edges, to be resolved below. RP_1 and RP_A, which should be "connected" and thus exactly overlapping, are now in different places.
  2. Delete the other edge RoadPoint(s) on the other connected containers meant to connect to this container
    • In this scenario, this means deleting RP_A on ContainerB.
  3. Select "Refresh Roads" from the Roads menu with the RoadManager selected (or, run once for each of the RoadContainers in question). This will automatically break the virtual connection between the containers
  4. In Add Mode, re-connect the containers (which will result in a new RoadPoint being added).
    • Select RP_B, which the deleted RoadPoint used to be connected to
    • Click while hovering over RP_1 in ContainerA
    • This will add a new RoadPoint inside Container B, at the position of, and with connections to, RP_1 of ContainerA.