feat: player can now enter train.

This commit is contained in:
tiger tiger tiger 2026-01-20 21:07:41 +01:00
parent 88cb69fc88
commit 4b07eaf6c5
3 changed files with 75 additions and 55 deletions

View File

@ -1,4 +1,4 @@
## A dolly tweens all contents to and from two destination points, and to its origin. ## A dolly tweens all contents to and from two destination points, and to its origin.
class_name Dolly class_name Dolly
extends Node3D extends Node3D
@ -11,9 +11,9 @@ extends Node3D
@export var post_leave_time : float = 5.0 @export var post_leave_time : float = 5.0
@onready var origination : Node3D = $Origination @onready var origination : Node3D = $Origination
@onready var destination : Node3D = $Destination @onready var destination : Node3D = $Destination
@onready var subway : SubwayTrain = %Subway @onready var subway : SubwayTrain = $Train
var tween : Tween = null var tween : Tween = null
@ -22,13 +22,23 @@ func _ready() -> void:
for child in get_children(true): for child in get_children(true):
if not child.visible: continue if not child.visible: continue
child.global_position = origination.global_position child.global_position = origination.global_position
## One arrival and departure ## One arrival and departure
func cycle() -> void: func cycle() -> void:
await arrive() await arrive()
await leave() await leave()
func _seat_player_if_inside() -> void:
if %EntryDetect.overlaps_body(State.player):
prints("Player is inside Train on", self.name)
State.player.sleeping = true
var s1 := %Seat1
var s2 := %Seat2
var seat : Node3D = s1 if (s1.global_position-State.player.global_position).length() < (s2.global_position-State.player.global_position).length() else s2
State.player.reparent(seat)
func arrive() -> void: func arrive() -> void:
%SubwayTrainAudio.play(0) %SubwayTrainAudio.play(0)
@ -40,13 +50,14 @@ func arrive() -> void:
if not child.visible: continue if not child.visible: continue
tween.parallel().tween_property(child, "global_position", self.global_position, arrival_time) tween.parallel().tween_property(child, "global_position", self.global_position, arrival_time)
await tween.finished await tween.finished
subway.door_open = true subway.door_open = true
func leave() -> void: func leave() -> void:
await get_tree().create_timer(pre_leave_time).timeout await get_tree().create_timer(pre_leave_time).timeout
subway.door_open = false subway.door_open = false
await get_tree().create_timer(door_close_time).timeout await get_tree().create_timer(door_close_time).timeout
_seat_player_if_inside()
if tween: tween.kill() if tween: tween.kill()
tween = create_tween().set_trans(Tween.TRANS_QUART).set_ease(Tween.EASE_IN) tween = create_tween().set_trans(Tween.TRANS_QUART).set_ease(Tween.EASE_IN)
for child in get_children(true): for child in get_children(true):

View File

@ -6,6 +6,12 @@ class_name SubwayTrain
if door_open == open: return if door_open == open: return
door_open=open door_open=open
if open: if open:
$AnimationPlayer.play("door_open") $Subway/AnimationPlayer.play("door_open")
else: else:
$AnimationPlayer.play("door_close") $Subway/AnimationPlayer.play("door_close")
func _ready() -> void:
$Subway/AnimationPlayer.animation_finished.connect(_on_animation_finished)
func _on_animation_finished(_discard) -> void:
%FrontWallClosed.disabled = door_open

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=22 format=3 uid="uid://df3ur5wll8vx7"] [gd_scene load_steps=23 format=3 uid="uid://df3ur5wll8vx7"]
[ext_resource type="PackedScene" uid="uid://4j1tlhfm3p40" path="res://base-environments/transition/subway_train.tscn" id="1_2h2xx"] [ext_resource type="PackedScene" uid="uid://4j1tlhfm3p40" path="res://base-environments/transition/subway_train.tscn" id="1_2h2xx"]
[ext_resource type="Script" uid="uid://dgfje4druu3sw" path="res://base-environments/transition/code/dolly.gd" id="1_5jpg8"] [ext_resource type="Script" uid="uid://dgfje4druu3sw" path="res://base-environments/transition/code/dolly.gd" id="1_5jpg8"]
[ext_resource type="Script" uid="uid://cyohujvfoiof7" path="res://base-environments/transition/code/subway_train.gd" id="2_aacjs"]
[ext_resource type="AudioStream" uid="uid://cwfr6sgcwg7sl" path="res://base-environments/transition/audio/450918__kyles__metro-subway-montreal-verdun-station-arrive-and-leave-semidistant-from-bridge-over-tracks-overpass.ogg" id="3_4h0n7"] [ext_resource type="AudioStream" uid="uid://cwfr6sgcwg7sl" path="res://base-environments/transition/audio/450918__kyles__metro-subway-montreal-verdun-station-arrive-and-leave-semidistant-from-bridge-over-tracks-overpass.ogg" id="3_4h0n7"]
[sub_resource type="Shader" id="Shader_tpaj8"] [sub_resource type="Shader" id="Shader_tpaj8"]
@ -79,24 +80,24 @@ shader_parameter/vertical_emission = SubResource("GradientTexture1D_v43sq")
[sub_resource type="BoxShape3D" id="BoxShape3D_5jpg8"] [sub_resource type="BoxShape3D" id="BoxShape3D_5jpg8"]
size = Vector3(1.565918, 2.3292236, 3.8251343) size = Vector3(1.565918, 2.3292236, 3.8251343)
[sub_resource type="BoxShape3D" id="BoxShape3D_e1qmr"]
size = Vector3(30.492157, 4.4813232, 3.4832764)
[sub_resource type="BoxShape3D" id="BoxShape3D_aacjs"] [sub_resource type="BoxShape3D" id="BoxShape3D_aacjs"]
size = Vector3(31.245972, 4.7752075, 1) size = Vector3(31.245972, 4.7752075, 1)
[sub_resource type="BoxShape3D" id="BoxShape3D_4h0n7"] [sub_resource type="BoxShape3D" id="BoxShape3D_4h0n7"]
size = Vector3(16.2845, 4.7752075, 1) size = Vector3(16.285, 4.775, 3)
[sub_resource type="BoxShape3D" id="BoxShape3D_xhnml"] [sub_resource type="BoxShape3D" id="BoxShape3D_xhnml"]
size = Vector3(6.0409546, 4.7752075, 1) size = Vector3(6.041, 4.775, 3)
[sub_resource type="BoxShape3D" id="BoxShape3D_5b47p"] [sub_resource type="BoxShape3D" id="BoxShape3D_5b47p"]
size = Vector3(5.908142, 4.7752075, 1) size = Vector3(5.908, 4.775, 3)
[sub_resource type="SphereShape3D" id="SphereShape3D_5jpg8"] [sub_resource type="SphereShape3D" id="SphereShape3D_5jpg8"]
radius = 2.0 radius = 2.0
[sub_resource type="BoxShape3D" id="BoxShape3D_e1qmr"]
size = Vector3(30.492157, 4.4813232, 3.4832764)
[node name="TrainDolly" type="Node3D"] [node name="TrainDolly" type="Node3D"]
script = ExtResource("1_5jpg8") script = ExtResource("1_5jpg8")
metadata/_custom_type_script = "uid://dgfje4druu3sw" metadata/_custom_type_script = "uid://dgfje4druu3sw"
@ -109,8 +110,9 @@ visible = false
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -150) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -150)
visible = false visible = false
[node name="Train" type="Node3D" parent="."] [node name="Train" type="AnimatableBody3D" parent="."]
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 0, 0, 0) transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 0, 0, 0)
script = ExtResource("2_aacjs")
[node name="ParticleScreen" type="MeshInstance3D" parent="Train"] [node name="ParticleScreen" type="MeshInstance3D" parent="Train"]
transform = Transform3D(-42.01, 4.0756225e-07, 4.340116e-07, -6.330816e-06, -2.8743172, -0.1808367, -5.9450595e-06, 0.1808367, -2.8743172, -3.9468384, 1.286, 2.488358) transform = Transform3D(-42.01, 4.0756225e-07, 4.340116e-07, -6.330816e-06, -2.8743172, -0.1808367, -5.9450595e-06, 0.1808367, -2.8743172, -3.9468384, 1.286, 2.488358)
@ -119,58 +121,28 @@ material_override = SubResource("ShaderMaterial_0vobo")
mesh = SubResource("QuadMesh_ppxbm") mesh = SubResource("QuadMesh_ppxbm")
[node name="Subway" parent="Train" instance=ExtResource("1_2h2xx")] [node name="Subway" parent="Train" instance=ExtResource("1_2h2xx")]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.7804413, 0, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.7804413, 0, 0)
script = null
[node name="EntryDetect" type="Area3D" parent="Train"] [node name="EntryDetect" type="Area3D" parent="Train"]
unique_name_in_owner = true
[node name="Shape1" type="CollisionShape3D" parent="Train/EntryDetect"] [node name="EntryShape1" type="CollisionShape3D" parent="Train/EntryDetect"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -8.105429, 1.1704571, 0.0023494991) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -8.105429, 1.1704571, 0.0023494991)
shape = SubResource("BoxShape3D_5jpg8") shape = SubResource("BoxShape3D_5jpg8")
[node name="Seat1" type="Node3D" parent="Train/EntryDetect/Shape1"] [node name="Seat1" type="Node3D" parent="Train/EntryDetect/EntryShape1"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00042915344, -1.042389, 3.5422485e-07) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00042915344, -1.042389, 3.5422485e-07)
[node name="Shape2" type="CollisionShape3D" parent="Train/EntryDetect"] [node name="EntryShape2" type="CollisionShape3D" parent="Train/EntryDetect"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 9.689882, 1.1704571, 4.236329e-07) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 9.689882, 1.1704571, 4.236329e-07)
shape = SubResource("BoxShape3D_5jpg8") shape = SubResource("BoxShape3D_5jpg8")
[node name="Seat2" type="Node3D" parent="Train/EntryDetect/Shape2"] [node name="Seat2" type="Node3D" parent="Train/EntryDetect/EntryShape2"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00042915344, -1.042389, 3.5422485e-07) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00042915344, -1.042389, 3.5422485e-07)
[node name="ClosedCollider" type="AnimatableBody3D" parent="Train"]
[node name="FrontWallClosed" type="CollisionShape3D" parent="Train/ClosedCollider"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.8395386, 1.4940796, -1.533)
shape = SubResource("BoxShape3D_aacjs")
disabled = true
[node name="FrontWallOpen1" type="CollisionShape3D" parent="Train/ClosedCollider"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.8054885, 1.4940796, -1.533)
shape = SubResource("BoxShape3D_4h0n7")
[node name="FrontWallOpen2" type="CollisionShape3D" parent="Train/ClosedCollider"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 13.442047, 1.4940796, -1.533)
shape = SubResource("BoxShape3D_xhnml")
[node name="FrontWallOpen3" type="CollisionShape3D" parent="Train/ClosedCollider"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -11.829376, 1.4940796, -1.533)
shape = SubResource("BoxShape3D_5b47p")
[node name="RearWall" type="CollisionShape3D" parent="Train/ClosedCollider"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.344, 1.457)
shape = SubResource("BoxShape3D_aacjs")
[node name="DriverCabin1" type="CollisionShape3D" parent="Train/ClosedCollider"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15.448963, 1.0697384, 0)
shape = SubResource("SphereShape3D_5jpg8")
disabled = true
[node name="DriverCabin2" type="CollisionShape3D" parent="Train/ClosedCollider"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -13.730333, 1.0697384, 0)
shape = SubResource("SphereShape3D_5jpg8")
disabled = true
[node name="SubwayTrainAudio" type="AudioStreamPlayer3D" parent="Train"] [node name="SubwayTrainAudio" type="AudioStreamPlayer3D" parent="Train"]
unique_name_in_owner = true unique_name_in_owner = true
stream = ExtResource("3_4h0n7") stream = ExtResource("3_4h0n7")
@ -203,3 +175,34 @@ spot_angle = 15.0
[node name="CollisionShape3D" type="CollisionShape3D" parent="Train/SubwaySoundAttenuationArea"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Train/SubwaySoundAttenuationArea"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.6517792, 1.7406616, 0.034606963) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.6517792, 1.7406616, 0.034606963)
shape = SubResource("BoxShape3D_e1qmr") shape = SubResource("BoxShape3D_e1qmr")
[node name="FrontWallClosed" type="CollisionShape3D" parent="Train"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.8395386, 1.4940796, -1.533)
shape = SubResource("BoxShape3D_aacjs")
[node name="FrontWallOpen1" type="CollisionShape3D" parent="Train"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.80548847, 1.4940796, 0)
shape = SubResource("BoxShape3D_4h0n7")
[node name="FrontWallOpen2" type="CollisionShape3D" parent="Train"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 13.442047, 1.4940796, 0)
shape = SubResource("BoxShape3D_xhnml")
[node name="FrontWallOpen3" type="CollisionShape3D" parent="Train"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -11.829376, 1.4940796, 0)
shape = SubResource("BoxShape3D_5b47p")
[node name="RearWall" type="CollisionShape3D" parent="Train"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.344, 1.457)
shape = SubResource("BoxShape3D_aacjs")
[node name="DriverCabin1" type="CollisionShape3D" parent="Train"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15.448963, 1.0697384, 0)
shape = SubResource("SphereShape3D_5jpg8")
disabled = true
[node name="DriverCabin2" type="CollisionShape3D" parent="Train"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -13.730333, 1.0697384, 0)
shape = SubResource("SphereShape3D_5jpg8")
disabled = true