feat: preventing players from leaving the playable area

This commit is contained in:
DottsGit
2026-06-06 12:44:16 -04:00
parent 64e024eb32
commit 5f2c2462e2
3 changed files with 126 additions and 15 deletions
+28 -15
View File
@@ -79,25 +79,25 @@ func _build_dust2_layout() -> void:
# Helper function to carve a precise slope (no lips or hard stops)
var carve_ramp = func(start_pos: Vector3, width: float, length: float, height: float, is_x_axis: bool, reverse: bool):
var box = CSGBox3D.new()
box.operation = CSGShape3D.OPERATION_SUBTRACTION
var ramp_box = CSGBox3D.new()
ramp_box.operation = CSGShape3D.OPERATION_SUBTRACTION
var slope = atan2(height, length)
var dir = 1.0 if reverse else -1.0
if not is_x_axis: # Ramp goes along Z
box.size = Vector3(width, 50, 50)
box.rotation.x = slope * dir
ramp_box.size = Vector3(width, 50, 50)
ramp_box.rotation.x = slope * dir
var mid_point = start_pos + Vector3(0, height / 2.0, (length / 2.0) * dir)
box.position = mid_point + (Vector3.UP.rotated(Vector3.RIGHT, box.rotation.x) * 25.0)
ramp_box.position = mid_point + (Vector3.UP.rotated(Vector3.RIGHT, ramp_box.rotation.x) * 25.0)
else: # Ramp goes along X
box.size = Vector3(50, 50, width)
box.rotation.z = -slope * dir
ramp_box.size = Vector3(50, 50, width)
ramp_box.rotation.z = -slope * dir
var mid_point = start_pos + Vector3((length / 2.0) * dir, height / 2.0, 0)
box.position = mid_point + (Vector3.UP.rotated(Vector3.FORWARD, box.rotation.z) * 25.0)
ramp_box.position = mid_point + (Vector3.UP.rotated(Vector3.FORWARD, ramp_box.rotation.z) * 25.0)
root_csg.add_child(box)
return box
root_csg.add_child(ramp_box)
return ramp_box
# ---------------------------------------------------------
# LAYOUT (with generous overlaps to prevent getting stuck)
@@ -172,11 +172,11 @@ func _build_dust2_layout() -> void:
carve_ramp.call(Vector3(5, 0, 5), 8.0, 12.0, 4.0, true, true)
# Floor
var floor = CSGBox3D.new()
floor.size = Vector3(140, 1, 140)
floor.position = Vector3(0, -0.5, 0)
floor.material = floor_mat
root_csg.add_child(floor)
var floor_box = CSGBox3D.new()
floor_box.size = Vector3(140, 1, 140)
floor_box.position = Vector3(0, -0.5, 0)
floor_box.material = floor_mat
root_csg.add_child(floor_box)
# Cover Boxes
var add_box = func(pos: Vector3, size: Vector3):
@@ -193,6 +193,19 @@ func _build_dust2_layout() -> void:
# Dummies
_build_dust2_dummies()
# Combat Area Bounds
var combat_area = load("res://entities/combat_area.gd").new()
combat_area.name = "CombatArea"
var area_shape = CollisionShape3D.new()
var cbox = BoxShape3D.new()
# Size the combat area to envelop the entire playable space (width and depth of 120, height of 20)
cbox.size = Vector3(120, 20, 120)
area_shape.shape = cbox
combat_area.add_child(area_shape)
# Center it on the map so it fits perfectly around the CSG boundaries
combat_area.position = Vector3(0, 10, 0)
add_child(combat_area)
func _build_dust2_dummies() -> void:
var spawn_dummy = func(pos: Vector3, rot_y: float):