upd rails and add new train and wagon
This commit is contained in:
@@ -520,17 +520,15 @@ func _update_wagon_progress_offsets() -> void:
|
||||
|
||||
for wagon in wagon_instances:
|
||||
var wagon_length: float = _get_vehicle_length(wagon)
|
||||
accumulated_distance += _get_wagon_spacing(previous_length, wagon_length)
|
||||
if wagon_spacing_override > 0.0:
|
||||
accumulated_distance += wagon_spacing_override + wagon_gap
|
||||
else:
|
||||
var detected_spacing: float = previous_length * 0.5 + wagon_length * 0.5
|
||||
accumulated_distance += detected_spacing * wagon_spacing_scale + wagon_gap
|
||||
|
||||
wagon_progress_offsets.append(accumulated_distance)
|
||||
previous_length = wagon_length
|
||||
|
||||
func _get_wagon_spacing(previous_length: float, wagon_length: float) -> float:
|
||||
if wagon_spacing_override > 0.0:
|
||||
return wagon_spacing_override + wagon_gap
|
||||
|
||||
var detected_spacing: float = previous_length * 0.5 + wagon_length * 0.5
|
||||
return detected_spacing * wagon_spacing_scale + wagon_gap
|
||||
|
||||
func _snap_wagons_to_progress(total_length: float = 0.0) -> void:
|
||||
if curve == null or wagon_instances.is_empty():
|
||||
return
|
||||
@@ -554,18 +552,16 @@ func _snap_wagons_to_progress(total_length: float = 0.0) -> void:
|
||||
wagon_offset = wagon_progress_offsets[i]
|
||||
|
||||
var wagon_progress: float = train_progress - direction * wagon_offset
|
||||
_snap_vehicle_to_progress(wagon, wagon_progress, total_length)
|
||||
|
||||
func _snap_vehicle_to_progress(vehicle: Node3D, progress: float, total_length: float) -> void:
|
||||
var vehicle_progress: float = wrapf(progress, 0.0, total_length)
|
||||
var center_position: Vector3 = to_global(curve.sample_baked(vehicle_progress, true))
|
||||
var prog_forward: float = wrapf(vehicle_progress + 2.0, 0.0, total_length)
|
||||
var forward_position: Vector3 = to_global(curve.sample_baked(prog_forward, true))
|
||||
var vehicle_progress: float = wrapf(wagon_progress, 0.0, total_length)
|
||||
var center_position: Vector3 = to_global(curve.sample_baked(vehicle_progress, true))
|
||||
var prog_forward: float = wrapf(vehicle_progress + 2.0, 0.0, total_length)
|
||||
var forward_position: Vector3 = to_global(curve.sample_baked(prog_forward, true))
|
||||
|
||||
vehicle.global_position = center_position
|
||||
if center_position.distance_to(forward_position) > 0.01:
|
||||
vehicle.look_at(forward_position, Vector3.UP)
|
||||
vehicle.rotate_y(PI)
|
||||
wagon.global_position = center_position
|
||||
if center_position.distance_to(forward_position) > 0.01:
|
||||
wagon.look_at(forward_position, Vector3.UP)
|
||||
wagon.rotate_y(PI)
|
||||
|
||||
func _get_vehicle_length(vehicle: Node3D) -> float:
|
||||
var bounds: AABB = _get_node_local_bounds(vehicle, vehicle)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[gd_resource type="Resource" script_class="WagonPool" format=3 uid="uid://bjnytgwt8tmf4"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dvk3bytqn3m5s" path="res://tgcc/train/main_train.tscn" id="1_t6q5r"]
|
||||
[ext_resource type="Script" uid="uid://b6xk0gtn2pwa" path="res://core/biome_generator/wagon_pool.gd" id="2_x6bmc"]
|
||||
[ext_resource type="PackedScene" uid="uid://bny4kv08j8j40" path="res://tgcc/train/wagon.tscn" id="1_t6q5r"]
|
||||
[ext_resource type="Script" uid="uid://c3bgupfogjvv2" path="res://core/biome_generator/wagon_pool.gd" id="2_x6bmc"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("2_x6bmc")
|
||||
|
||||
Reference in New Issue
Block a user