Skip to content

Class: RoadPoint

Patrick W. Crawford edited this page Oct 3, 2024 · 4 revisions

You will be spending most of your time most likely using RoadPoints, either from code or in the UI.

roadpoint editor

Usage

There are two main ways to update RoadPoints:

A) Inspector pannel

All controls of a RoadPoint are available in the inspector panel. It is currently split into two sections.

Edit RoadPoint section

  • Select [Next/Prior] RoadPoint: On press, will update your editor selection to be the next or previous RoadPoint. Hold shift jump to the last RoadPoint in this direction.
  • + [Next/Prior] RoadPoint: If the [last/first] RoadPoint is selected, then this button is displayed instead as a quick way to add another RoadPoint with the same settings. Hold shift to jump to the first RoadPoint in this direction.
  • + icon: Add another lane to this side of the road. Hold shift to affect all RoadPoints in this RoadContainer.
  • - icon: Remove another lane from this side of the road. Hold shift to affect all RoadPoints in this RoadContainer.
  • Yellow ||: This is not a button, just a visual indicator separating the controls affecting the "reverse" (left side) controls from the "forward" (right side).
  • Copy/Apply Setting(s): This will copy all attributes of the initially selected RoadPoint, such as lane count and shoulder widths, and then lets you apply that to another RoadPoint once selected. Similar to the other bulk tools, holding shift means Apply will make the changes for all RoadPoints on this container. This is a fast way to assign the same lane counts and directions for the entire RoadContainer (or another RoadContainer).

If you hold shift, the buttons above will turn into "bulk operations". Adding/removing a lane will apply to all RoadPoints in the same RoadContainer.

B) 3D view widgets

A subset of the most convenient controls for a RoadPoint are available directly in the 3D view, via widgets.

Lane count slider

The blue dot gizmos slide in and out from the RoadPoint to change the number of lanes for that RoadPoint.

Magnitude in/out

The orange/red dot in the direction the road is going/coming from represents the bezier curve handler magnitudes. Pulling this handle further away from the center of the RoadPoint will result in a larger, smoother curve coming out of this RoadPoint.

Edit RoadPoints from code

As long as you add a RoadPoint to a child a RoadContainer, you are free to do and change what you like out of the provided export variables. Most common operations will include the following (godot 3.5 code below; for a 4.x example, see the Procedural Demo here)

# Add a RoadPoint
var new_rp = RoadPoint.new()

# Be sure to add as a child to a RoadContaineralready in your scene.
# You can fetch all RoadContainers via RoadManager's `get_containers()` function.
var container: RoadContainer
container.add_child(new_rp)

# Set the number of lanes: 1 reverse, 2 forward
new_rp.traffic_dir = [RoadPoint.LaneDir.REVERSE, RoadPoint.LaneDir.FORWARD, RoadPoint.LaneDir.FORWARD]

# Most importantly, you need to connect this roadpoint to some existing ones.
# Here, we're just getting the reference of some random existing point
var target_point: RoadPoint = container.get_children()[0]

# Connect them to each other, specifying which "side" of the RoadPoints should be connected.
# By connecting one RP's "next" to the following's "prior", you ensure that the flow/direction of RoadPoints is always in the same direction. Technically this shoudln't matter, but some edges can arise when pointing RP's in opposite directions.
var this_direction = RoadPoint.PointInit.NEXT
var target_direction = RoadPoint.PointInit.PRIOR
new_rp.connect_roadpoint(this_direction, target_point, target_direction)

# You can also do this in a low-level way, though is less recommended as it may get in the way of plugin internals:

target_point.next_pt_init = target_point.get_path_to(new_rp)
new_rp.prior_pt_init = new_rp.get_path_to(target_point)

# To disconnect a RoadPoint, you only need to specify which direction on this node you'd like to disconnect and the target's direction to disconnect. You need to specify the target's direction as technically the same RoadPoint could be both the PRIO and NEXT endpoint, if making a tight circle.

new_rp.disconnect_roadpoint(this_direction, target_direction)

Public functions

Settings

These are all export nodes directly from the RoadPoint script.

  • traffic_dir (array of enums): The primary field which determines the number of lanes on the road. The panel buttons above as well as the 3D viewport widget simply hook in to edit this value to add or remove nodes of the according type.
    • Values must match the Enum class LaneDir.
    • Note: There is little or no functionality yet with the BOTH selection, and the NONE is functioanlly a no-op.
  • auto_lanes (bool): Auto assign lane textures based on the sequence of traffic directions above. Most users will want to keep this setting on.
  • lanes (array of enums): Do not edit if auto lanes is on, which is the recommended value. Can be used to manually override the texture used for a lane.
  • lane_width (float): Change how wide (in meters) each lane of traffic is.
  • shoulder_width_l (float): Define how wide the left ("reverse") shoulder is before the gutter bevel. If too large, will have visible texture stretching.
  • shoulder_width_r (float): Define how wide the right ("forward") shoulder is before the gutter bevel. If too large, will have visible texture stretching.
  • gutter_profile (2d vector): Define the shape of the tapered edge of the road. Vector represents the position to offset the vertex before extrusion.
  • prior_pt_init (NodePath): Defines the next RoadPoint in the chain. If empty, then this is an open edge.
  • terminated (bool): Flag to indicate that this RoadPoint should not be ever considered as an "edge" for this RoadContainer, and thus not open for connecting to.
  • next_pt_init (NodePath): Defines the prior RoadPoint in the chain. If empty, then this is an open edge.
  • prior_mag (float): Value is passed into the internal bezier curve "in" handle, aligned to the RoadPoint orientation. Making this value larger will make the the RoadSegment ease more into this RoadPoint from the prior RoadPoint.
  • next_mag (float): Value is passed into the internal bezier curve "out" handle, aligned to the RoadPoint orientation. Making this value larger will make the the RoadSegment ease more into this RoadPoint from the next RoadPoint.
  • create_geo (bool): If disabled, then the child RoadSegment will not generate any meshes or colliders. If the parent RoadContainer has generate road lanes enabled, then these lanes will still be created even if create_geo is off. This allows you to slot in your own custom meshes.