fix rail switch

This commit is contained in:
Overside srl
2026-02-01 11:22:46 +01:00
parent c1ce3b06f4
commit dd1ba0fa9a
5 changed files with 58 additions and 24 deletions

View File

@@ -18,7 +18,7 @@ albedo_color = Color(2.153851e-06, 0.25305444, 0.03645257, 1)
[sub_resource type="Curve3D" id="Curve3D_0b1nv"] [sub_resource type="Curve3D" id="Curve3D_0b1nv"]
closed = true closed = true
_data = { _data = {
"points": PackedVector3Array(-2.1678085, -0.043792725, 1.658886, 2.1678085, 0.043792725, -1.658886, -41.962486, 0.03566742, -44.78871, 0, 0, 0, 0, 0, 0, -7.760188, 0.036315918, -45.60305, -6.559948, 0.007423401, -0.16356277, 6.559948, -0.007423401, 0.16356277, 21.603975, 0.03604126, -45.26774, -3.4513588, 0.124176025, -4.544277, 3.4513588, -0.124176025, 4.544277, 40.931072, 0.032211304, -40.35701, 0.5563507, 0.09750366, -3.6268482, -0.5563507, -0.09750366, 3.6268482, 45.43544, 0.021453857, -26.947992, 3.438774, 0.09018707, -3.405755, -3.438774, -0.09018707, 3.405755, 38.412643, 0.47789, -9.150471, 6.6514378, -0.022911072, 0.7331085, -6.6514378, 0.022911072, -0.7331085, 26.96904, 0.003112793, -3.9279928, 5.315757, -0.10071564, 3.6390858, -5.315757, 0.10071564, -3.6390858, 3.4968712, 0.0079574585, -10.011598, 4.9409637, -0.0754776, 2.709568, -4.9409637, 0.0754776, -2.709568, -3.8321874, 0.024543762, -30.849133, 6.360344, 0.0488739, -1.9223251, -6.360344, -0.0488739, 1.9223251, -22.311077, 0.005493164, -31.887383, -0.9378357, 0.12989807, -4.797656, 0.9378357, -0.12989807, 4.797656, -31.28027, 0.015075684, -18.969343, -7.12364, 0.096969604, -3.4738579, 7.12364, -0.096969604, 3.4738579, -23.472174, 0.003479004, -4.4070177, -9.224047, 0.08418274, -2.961853, 9.224047, -0.08418274, 2.961853, 12.167218, -0.011207581, 14.035401, -8.825874, 0.03265381, -1.0564928, 8.825874, -0.03265381, 1.0564928, 32.632145, -0.011894226, 14.993831, 0, 0, 0, 0, 0, 0, 39.98447, -0.019104004, 24.146927, 4.9879036, 0.122177124, -4.6163826, -4.9879036, -0.122177124, 4.6163826, 35.724655, 0.047676086, 33.444454, 8.1661625, 0.014076233, -0.6628723, -8.1661625, -0.014076233, 0.6628723, 11.495622, 0.0951767, 40.647045, 4.9570847, -0.058029175, 2.0650558, -4.9570847, 0.058029175, -2.0650558, -22.318954, 0.051948547, 40.504288, 4.9869003, -0.18069458, 6.610588, -4.9869003, 0.18069458, -6.610588, -37.494194, 0.080329895, 26.992659, -1.5943985, -0.19984436, 7.435757, 1.5943985, 0.19984436, -7.435757, -46.58226, 0.10346222, 8.63745, -0.4270401, -0.16287994, 6.045038, 0.4270401, 0.16287994, -6.045038, -39.930115, 0.050865173, -11.514841, 4.8086166, -0.20992279, 7.687052, -4.8086166, 0.20992279, -7.687052, -35.56163, 0.15759277, -32.8561, -0.73628235, -0.15232849, 5.656826, 0.73628235, 0.15232849, -5.656826, -45.566254, 1.1692886, -39.59991), "points": PackedVector3Array(-2.1678085, -0.043792725, 1.658886, 2.1678085, 0.043792725, -1.658886, -41.962486, 0.03566742, -44.78871, 0, 0, 0, 0, 0, 0, -7.760188, 0.036315918, -45.60305, -6.559948, 0.007423401, -0.16356277, 6.559948, -0.007423401, 0.16356277, 21.603975, 0.03604126, -45.26774, -3.4513588, 0.124176025, -4.544277, 3.4513588, -0.124176025, 4.544277, 40.931072, 0.032211304, -40.35701, 0.5563507, 0.09750366, -3.6268482, -0.5563507, -0.09750366, 3.6268482, 45.43544, 0.021453857, -26.947992, 3.438774, 0.09018707, -3.405755, -3.438774, -0.09018707, 3.405755, 38.412643, 0.47789, -9.150471, 6.6514378, -0.022911072, 0.7331085, -6.6514378, 0.022911072, -0.7331085, 25.856459, 0.10243797, -3.7440395, 5.315757, -0.10071564, 3.6390858, -5.315757, 0.10071564, -3.6390858, 3.4968712, 0.0079574585, -10.011598, 4.9409637, -0.0754776, 2.709568, -4.9409637, 0.0754776, -2.709568, -3.8321874, 0.024543762, -30.849133, 6.360344, 0.0488739, -1.9223251, -6.360344, -0.0488739, 1.9223251, -22.311077, 0.005493164, -31.887383, -0.9378357, 0.12989807, -4.797656, 0.9378357, -0.12989807, 4.797656, -31.28027, 0.015075684, -18.969343, -7.12364, 0.096969604, -3.4738579, 7.12364, -0.096969604, 3.4738579, -23.472174, 0.003479004, -4.4070177, -9.224047, 0.08418274, -2.961853, 9.224047, -0.08418274, 2.961853, 12.167218, -0.011207581, 14.035401, -8.825874, 0.03265381, -1.0564928, 8.825874, -0.03265381, 1.0564928, 32.632145, -0.011894226, 14.993831, 0, 0, 0, 0, 0, 0, 39.98447, -0.019104004, 24.146927, 4.9879036, 0.122177124, -4.6163826, -4.9879036, -0.122177124, 4.6163826, 35.724655, 0.047676086, 33.444454, 8.1661625, 0.014076233, -0.6628723, -8.1661625, -0.014076233, 0.6628723, 11.495622, 0.0951767, 40.647045, 4.9570847, -0.058029175, 2.0650558, -4.9570847, 0.058029175, -2.0650558, -22.318954, 0.051948547, 40.504288, 4.9869003, -0.18069458, 6.610588, -4.9869003, 0.18069458, -6.610588, -37.494194, 0.080329895, 26.992659, -1.5943985, -0.19984436, 7.435757, 1.5943985, 0.19984436, -7.435757, -46.58226, 0.10346222, 8.63745, -0.4270401, -0.16287994, 6.045038, 0.4270401, 0.16287994, -6.045038, -39.930115, 0.050865173, -11.514841, 4.8086166, -0.20992279, 7.687052, -4.8086166, 0.20992279, -7.687052, -35.56163, 0.15759277, -32.8561, -0.73628235, -0.15232849, 5.656826, 0.73628235, 0.15232849, -5.656826, -45.566254, 0.602231, -39.59991),
"tilts": PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) "tilts": PackedFloat32Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
} }
point_count = 23 point_count = 23
@@ -72,14 +72,6 @@ main_scene = ExtResource("2_0b1nv")
mesh = SubResource("PlaneMesh_23vqf") mesh = SubResource("PlaneMesh_23vqf")
surface_material_override/0 = SubResource("StandardMaterial3D_23vqf") surface_material_override/0 = SubResource("StandardMaterial3D_23vqf")
[node name="Train" type="MeshInstance3D" parent="Ground" unique_id=65189673 node_paths=PackedStringArray("rail_a", "rail_b")]
transform = Transform3D(0.6867333, -0.014397784, -0.89729905, 0, 1.1300678, -0.018126683, 0.8974134, 0.011017708, 0.68664587, -41.962486, 0.03566742, -44.78871)
mesh = ExtResource("3_jy5c4")
skeleton = NodePath("../Rails1/TrainEngine")
script = ExtResource("6_1lqs8")
rail_a = NodePath("../Rails1")
rail_b = NodePath("../Rails2")
[node name="Rails1" type="Path3D" parent="Ground" unique_id=1160818899] [node name="Rails1" type="Path3D" parent="Ground" unique_id=1160818899]
curve = SubResource("Curve3D_0b1nv") curve = SubResource("Curve3D_0b1nv")
@@ -131,7 +123,7 @@ path_joined = true
material = SubResource("StandardMaterial3D_ihlg3") material = SubResource("StandardMaterial3D_ihlg3")
[node name="TrainEngine" type="PathFollow3D" parent="Ground/Rails1" unique_id=973990755] [node name="TrainEngine" type="PathFollow3D" parent="Ground/Rails1" unique_id=973990755]
transform = Transform3D(0.6867333, -0.014397784, -0.89729905, 0, 1.1300678, -0.018126683, 0.8974134, 0.011017708, 0.68664587, -41.962486, 0.03566742, -44.78871) transform = Transform3D(0.6867339, -0.014397825, -0.8973005, 0, 1.130071, -0.018126711, 0.8974141, 0.01101774, 0.68664694, -41.962486, 0.03566742, -44.78871)
rotation_mode = 4 rotation_mode = 4
script = ExtResource("2_jgp6u") script = ExtResource("2_jgp6u")
@@ -190,6 +182,12 @@ transform = Transform3D(-0.39616987, 0.010450672, -1.0582525, 0, 1.1301593, 0.01
rotation_mode = 4 rotation_mode = 4
script = ExtResource("2_jgp6u") script = ExtResource("2_jgp6u")
[node name="Train" type="MeshInstance3D" parent="Ground" unique_id=65189673]
transform = Transform3D(0.6867333, -0.014397784, -0.89729905, 0, 1.1300678, -0.018126683, 0.8974134, 0.011017708, 0.68664587, -41.962486, 0.03566742, -44.78871)
mesh = ExtResource("3_jy5c4")
skeleton = NodePath("../Rails1/TrainEngine")
script = ExtResource("6_1lqs8")
[node name="RailSwtich" type="Area3D" parent="Ground" unique_id=1897237029 node_paths=PackedStringArray("rail_a", "rail_b", "switch_to_rail")] [node name="RailSwtich" type="Area3D" parent="Ground" unique_id=1897237029 node_paths=PackedStringArray("rail_a", "rail_b", "switch_to_rail")]
script = ExtResource("7_cenvf") script = ExtResource("7_cenvf")
rail_a = NodePath("../Rails1") rail_a = NodePath("../Rails1")
@@ -210,6 +208,7 @@ fov = 11.9
near = 0.001 near = 0.001
script = ExtResource("4_jy5c4") script = ExtResource("4_jy5c4")
train = NodePath("../Ground/Train") train = NodePath("../Ground/Train")
follow_distance = 30.0
[node name="HUD" type="Control" parent="." unique_id=563257159] [node name="HUD" type="Control" parent="." unique_id=563257159]
layout_mode = 3 layout_mode = 3
@@ -229,9 +228,9 @@ label_settings = SubResource("LabelSettings_1lqs8")
[node name="camera_label" type="Label" parent="HUD" unique_id=1719494020] [node name="camera_label" type="Label" parent="HUD" unique_id=1719494020]
layout_mode = 0 layout_mode = 0
offset_left = 20.0 offset_left = 19.0
offset_top = 43.0 offset_top = 43.0
offset_right = 1280.0 offset_right = 1279.0
offset_bottom = 66.0 offset_bottom = 66.0
size_flags_vertical = 0 size_flags_vertical = 0
text = "Camera: " text = "Camera: "
@@ -239,10 +238,10 @@ label_settings = SubResource("LabelSettings_1lqs8")
[node name="controls_label" type="Label" parent="HUD" unique_id=1262113688] [node name="controls_label" type="Label" parent="HUD" unique_id=1262113688]
layout_mode = 0 layout_mode = 0
offset_left = 20.0 offset_left = 19.0
offset_top = 64.0 offset_top = 83.0
offset_right = 1280.0 offset_right = 1279.0
offset_bottom = 217.0 offset_bottom = 236.0
size_flags_vertical = 0 size_flags_vertical = 0
text = "Comandi: text = "Comandi:
\"W / S - Accelera / Rallenta\", \"W / S - Accelera / Rallenta\",
@@ -251,3 +250,13 @@ text = "Comandi:
\"TAB\" - Cambia binario, \"TAB\" - Cambia binario,
\"ESC - Esci\"" \"ESC - Esci\""
label_settings = SubResource("LabelSettings_1lqs8") label_settings = SubResource("LabelSettings_1lqs8")
[node name="switch_label" type="Label" parent="HUD" unique_id=462391845]
layout_mode = 0
offset_left = 19.0
offset_top = 64.0
offset_right = 1279.0
offset_bottom = 87.0
size_flags_vertical = 0
text = "Binario: "
label_settings = SubResource("LabelSettings_1lqs8")

View File

@@ -11,4 +11,7 @@ func toggle_switch() -> void:
switch_to_rail = rail_b switch_to_rail = rail_b
else: else:
switch_to_rail = rail_a switch_to_rail = rail_a
#func get_state_name() -> String:
#return "BIANRIO 1" if current_state == SwitchState.LEFT else "BINARIO 2"

View File

@@ -9,8 +9,8 @@ signal rail_switched(old_rail: Path3D, new_rail: Path3D)
@export var max_speed: float = 50.0 @export var max_speed: float = 50.0
@export var min_speed: float = 3.0 @export var min_speed: float = 3.0
@export var acceleration: float = 12.0 @export var acceleration: float = 12.0
@export var rail_a: Path3D @onready var rail_a: Path3D = $"../Rails1"
@export var rail_b: Path3D @onready var rail_b: Path3D = $"../Rails2"
var current_follower: PathFollow3D var current_follower: PathFollow3D
var current_rail: Path3D var current_rail: Path3D
@@ -24,6 +24,7 @@ func _ready() -> void:
func _process(delta: float) -> void: func _process(delta: float) -> void:
_handle_input(delta) _handle_input(delta)
current_follower.progress += current_speed * delta current_follower.progress += current_speed * delta
global_transform = current_follower.global_transform
func _handle_input(delta: float) -> void: func _handle_input(delta: float) -> void:
@@ -48,8 +49,8 @@ func switch_to_rail(new_rail: Path3D) -> void:
var closest_offset = find_closest_point_on_path(new_rail, global_position) var closest_offset = find_closest_point_on_path(new_rail, global_position)
current_follower.progress = closest_offset current_follower.progress = closest_offset
func find_closest_point_on_path(path: Path3D, point: Vector3) -> float: func find_closest_point_on_path(path: Path3D, point: Vector3) -> float:
var curve = path.curve var curve = path.curve
var closest_offset = 0.0 var closest_offset = 0.0

View File

@@ -5,7 +5,9 @@ extends Node3D
@onready var camera_label : Label = $HUD/camera_label @onready var camera_label : Label = $HUD/camera_label
@onready var train: MeshInstance3D = $Ground/Train @onready var train: MeshInstance3D = $Ground/Train
@onready var camera: TrainControlCamera = $TrainCamera @onready var camera: TrainControlCamera = $TrainCamera
@onready var rail_switch: Area3D = $Ground/RailSwtich
@onready var switch_label : Label = $HUD/switch_label
func _process(_delta: float) -> void: func _process(_delta: float) -> void:
_update_ui() _update_ui()
@@ -14,9 +16,9 @@ func _process(_delta: float) -> void:
SceneSwitcher.switch_scene(main_scene.resource_path) SceneSwitcher.switch_scene(main_scene.resource_path)
if Input.is_action_just_pressed("change_train"): if Input.is_action_just_pressed("change_train"):
SceneSwitcher.switch_scene(main_scene.resource_path) _toggle_rail()
func _update_ui() -> void: func _update_ui() -> void:
if speed_label and train: if speed_label and train:
var kmh = train.get_speed() * 3.6 var kmh = train.get_speed() * 3.6
@@ -24,3 +26,22 @@ func _update_ui() -> void:
if camera_label and camera: if camera_label and camera:
camera_label.text = "Camera: %s" % camera.get_mode_name() camera_label.text = "Camera: %s" % camera.get_mode_name()
func _toggle_rail() -> void:
if train and rail_switch:
rail_switch.toggle_switch()
train.switch_to_rail(rail_switch.switch_to_rail)
func _update_switch_status():
if not switch_label:
return
#if rail_switch:
#var state_name = rail_switch.get_state_name()
#var color = Color.YELLOW if rail_switch.current_state == rail_switch.SwitchState.LEFT else Color.CYAN
#switch_label.text = "Scambio: %s" % state_name
#switch_label.add_theme_color_override("font_color", color)
#else:
#switch_label.text = "Scambio: N/A"