From ef6e306b3e25677a2a1d3e9ee6c9fd89e92c40a8 Mon Sep 17 00:00:00 2001 From: Dendy Faist Date: Fri, 6 Mar 2026 11:46:35 +0100 Subject: [PATCH] feat: Add world border to prevent the player from exiting the level --- level.gd | 33 ++++++++++++++++++++++++++++++++- level.tscn | 10 +++++++++- station.gd | 4 ---- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/level.gd b/level.gd index 398b4da..3367e1c 100644 --- a/level.gd +++ b/level.gd @@ -151,7 +151,35 @@ func initialize_world() -> void: chunk.exits[3] = true chunk.update() - + + + var wall_n = $WorldLimits/WallN + var wall_s = $WorldLimits/WallN.duplicate() + $WorldLimits.add_child(wall_s) + var wall_e = $WorldLimits/WallN.duplicate() + $WorldLimits.add_child(wall_e) + var wall_w = $WorldLimits/WallN.duplicate() + $WorldLimits.add_child(wall_w) + + wall_n.shape.size = Vector3( + Global.chunk_size * dimension, + 50, + 1 + ) + var WallCenter = Global.chunk_size/2 + wall_n.position.z = -WallCenter + wall_n.position.x = (Global.chunk_size*dimension)/2 - WallCenter + + wall_s.position.z = Global.chunk_size*dimension - WallCenter + wall_s.position.x = (Global.chunk_size*dimension)/2 - WallCenter + + wall_e.rotation.y = deg_to_rad(90) + wall_e.position.z = (Global.chunk_size*dimension)/2 - WallCenter + wall_e.position.x = Global.chunk_size*dimension - WallCenter + + wall_w.rotation.y = deg_to_rad(90) + wall_w.position.z = (Global.chunk_size*dimension)/2 - WallCenter + wall_w.position.x = -WallCenter @@ -184,4 +212,7 @@ func _on_player_station_reached(): for n in $ChunkContainer.get_children(): $ChunkContainer.remove_child(n) n.queue_free() + for n in $WorldLimits.get_children(): + if n.name != "WallN": + n.queue_free() initialize_world() diff --git a/level.tscn b/level.tscn index e382845..c48c61b 100644 --- a/level.tscn +++ b/level.tscn @@ -17,6 +17,9 @@ fog_density = 0.0 fog_sky_affect = 0.39 fog_height = 2.3 +[sub_resource type="BoxShape3D" id="BoxShape3D_0b4ue"] +size = Vector3(1, 50, 1) + [node name="Level" type="Node3D" unique_id=1248504413] script = ExtResource("1_0b4ue") @@ -27,7 +30,7 @@ environment = SubResource("Environment_vonw3") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.8361101, 0) [node name="Camera3D" type="Camera3D" parent="." unique_id=2083164402] -transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0, 56.95375, 0) +transform = Transform3D(1, 0, 0, 0, -4.371139e-08, 1, 0, -1, -4.371139e-08, 0, 703.6041, 0) current = true fov = 55.0 script = ExtResource("2_vonw3") @@ -57,4 +60,9 @@ fov = 55.0 size = 100.0 script = ExtResource("4_0b4ue") +[node name="WorldLimits" type="StaticBody3D" parent="." unique_id=697423258] + +[node name="WallN" type="CollisionShape3D" parent="WorldLimits" unique_id=1509447441] +shape = SubResource("BoxShape3D_0b4ue") + [connection signal="station_reached" from="Player" to="." method="_on_player_station_reached"] diff --git a/station.gd b/station.gd index 1379578..d5c4b21 100644 --- a/station.gd +++ b/station.gd @@ -2,7 +2,3 @@ extends Node3D func _ready() -> void: scale *= Global.chunk_size / 150 - #$Mesh.mesh.size.x = Global.chunk_size - #$Mesh.mesh.size.y = Global.chunk_size - #$StationArea/CollisionShape3D.shape.size.x = Global.chunk_size * 0.50 - #$StationArea/CollisionShape3D.shape.size.z = Global.chunk_size * 0.50