fix rail switch
This commit is contained in:
@@ -11,4 +11,7 @@ func toggle_switch() -> void:
|
||||
switch_to_rail = rail_b
|
||||
else:
|
||||
switch_to_rail = rail_a
|
||||
|
||||
|
||||
#func get_state_name() -> String:
|
||||
#return "BIANRIO 1" if current_state == SwitchState.LEFT else "BINARIO 2"
|
||||
|
||||
@@ -9,8 +9,8 @@ signal rail_switched(old_rail: Path3D, new_rail: Path3D)
|
||||
@export var max_speed: float = 50.0
|
||||
@export var min_speed: float = 3.0
|
||||
@export var acceleration: float = 12.0
|
||||
@export var rail_a: Path3D
|
||||
@export var rail_b: Path3D
|
||||
@onready var rail_a: Path3D = $"../Rails1"
|
||||
@onready var rail_b: Path3D = $"../Rails2"
|
||||
|
||||
var current_follower: PathFollow3D
|
||||
var current_rail: Path3D
|
||||
@@ -24,6 +24,7 @@ func _ready() -> void:
|
||||
func _process(delta: float) -> void:
|
||||
_handle_input(delta)
|
||||
current_follower.progress += current_speed * delta
|
||||
global_transform = current_follower.global_transform
|
||||
|
||||
|
||||
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)
|
||||
current_follower.progress = closest_offset
|
||||
|
||||
|
||||
|
||||
|
||||
func find_closest_point_on_path(path: Path3D, point: Vector3) -> float:
|
||||
var curve = path.curve
|
||||
var closest_offset = 0.0
|
||||
|
||||
@@ -5,7 +5,9 @@ extends Node3D
|
||||
@onready var camera_label : Label = $HUD/camera_label
|
||||
@onready var train: MeshInstance3D = $Ground/Train
|
||||
@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:
|
||||
_update_ui()
|
||||
@@ -14,9 +16,9 @@ func _process(_delta: float) -> void:
|
||||
SceneSwitcher.switch_scene(main_scene.resource_path)
|
||||
|
||||
if Input.is_action_just_pressed("change_train"):
|
||||
SceneSwitcher.switch_scene(main_scene.resource_path)
|
||||
|
||||
|
||||
_toggle_rail()
|
||||
|
||||
|
||||
func _update_ui() -> void:
|
||||
if speed_label and train:
|
||||
var kmh = train.get_speed() * 3.6
|
||||
@@ -24,3 +26,22 @@ func _update_ui() -> void:
|
||||
|
||||
if camera_label and camera:
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user