Skip to content

Commit

Permalink
Add new road type with less curves, try fix the transition bug betwee…
Browse files Browse the repository at this point in the history
…n the intersection and the connection.
  • Loading branch information
sairam4123 committed Oct 27, 2021
1 parent 20bbbfc commit 3e43c2a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
10 changes: 5 additions & 5 deletions building_system/building_placer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ func _input(event):
var expanded_aabb = new_building.get_aabb()
DrawingUtils.draw_box_with_aabb($"ImmediateGeometry", expanded_aabb)

func _process(delta):
print("------------------------------------------")
print_stray_nodes()
print("-------------------------------------------")
#func _process(delta):
# print("------------------------------------------")
# print_stray_nodes()
# print("-------------------------------------------")
#
# attempt - 1: failed
#var building_transform = Transform.IDENTITY
#building_transform.origin = point
Expand Down
4 changes: 3 additions & 1 deletion roads_system/RoadNetwork.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ class RoadNetworkInfo extends Resource:
export var length: float = 1
export var width: float = 0.5
export var end_radius: float = 0.5
export var curvature: float = 0.3
export var subdivide_length = 5.0

func _init(_id: String, _name: String, _length: float, _width: float, _end_radius: float, _subdivide_length = 5, lanes = []):
func _init(_id: String, _name: String, _length: float, _width: float, _end_radius: float, _curvature: float = 0.3, _subdivide_length = 5, lanes = []):
self.id = _id
self.name = _name
self.length = _length
self.width = _width
self.end_radius = _end_radius
self.curvature = _curvature
self.subdivide_length = _subdivide_length

func create_intersection(position: Vector3) -> RoadIntersection:
Expand Down
2 changes: 1 addition & 1 deletion roads_system/RoadRenderer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func draw_intersection(intersection: RoadIntersection):
direction = ((intersection.direction_to(connection.start_position) + connection.end_position.direction_to(intersection))).normalized()
var start_point = intersection.position
if intersection.connections.size() > 1:
start_point += direction * (intersection.road_network_info.length + ((connection.road_network_info.width)/2) + (pow(intersection.connections.size(), 0.8)/2.0))
start_point += direction * (connection.road_network_info.length + ((connection.road_network_info.width)/2) + (pow(intersection.connections.size(), connection.road_network_info.curvature)/2.0))
# print(intersection.road_network_info.length + (connection.road_network_info.width-1) + (pow(intersection.connections.size(), 0.3)/3.0))
start_points.append(start_point)
# DrawingUtils.draw_empty_circle($ImmediateGeometry, start_point, 0.25, Color.yellow)
Expand Down
5 changes: 4 additions & 1 deletion roads_system/RoadTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func _input(event):
is_curve_tool_on = false

if event.scancode == KEY_1:
current_info = RoadNetworkInfo.new("test_id", "Test Road", 1, 0.5, 1, [RoadLaneInfo.new(RoadNetwork.Direction.FORWARD, 0.25, 0.125), RoadLaneInfo.new(RoadNetwork.Direction.BACKWARD, 0.25, -0.125)])
current_info = RoadNetworkInfo.new("test_id", "Test Road", 1, 0.5, 1, 0.2, [RoadLaneInfo.new(RoadNetwork.Direction.FORWARD, 0.25, 0.125), RoadLaneInfo.new(RoadNetwork.Direction.BACKWARD, 0.25, -0.125)])
if event.scancode == KEY_2:
current_info = RoadNetworkInfo.new("test_id_2", "Test Road 2", 1, 1, 1)
if event.scancode == KEY_3:
Expand All @@ -59,6 +59,9 @@ func _input(event):
current_info = RoadNetworkInfo.new("test_id_4", "Test Road 4", 2, 1, 1)
if event.scancode == KEY_5:
current_info = RoadNetworkInfo.new("test_id_4", "Test Road 4", 1, 1, 1.5)
if event.scancode == KEY_6:
current_info = RoadNetworkInfo.new("test_id_5", "Test Road 5", 0.25, 0.5, 1, 0.01, [RoadLaneInfo.new(RoadNetwork.Direction.FORWARD, 0.25, 0.125), RoadLaneInfo.new(RoadNetwork.Direction.BACKWARD, 0.25, -0.125)])


if !enabled:
return
Expand Down
5 changes: 4 additions & 1 deletion roads_system/RoadUpgrade.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ onready var world_road_network: RoadNetwork = get_node(world_road_network_node)
const RoadIntersection = RoadNetwork.RoadIntersection
const RoadSegment = RoadNetwork.RoadSegment
const RoadNetworkInfo = RoadNetwork.RoadNetworkInfo
const RoadLaneInfo = RoadNetwork.RoadLaneInfo

var _snapped_segment

Expand Down Expand Up @@ -34,7 +35,9 @@ func _input(event):
current_info = RoadNetworkInfo.new("test_id_4", "Test Road 4", 2, 1, 1)
if event.scancode == KEY_5:
current_info = RoadNetworkInfo.new("test_id_4", "Test Road 4", 1, 1, 1.5)

if event.scancode == KEY_6:
current_info = RoadNetworkInfo.new("test_id_5", "Test Road 5", 0.25, 0.5, 1, 0.01, [RoadLaneInfo.new(RoadNetwork.Direction.FORWARD, 0.25, 0.125), RoadLaneInfo.new(RoadNetwork.Direction.BACKWARD, 0.25, -0.125)])


if !enabled:
return
Expand Down

0 comments on commit 3e43c2a

Please sign in to comment.