diff --git a/levels/game_shell.gd b/levels/game_shell.gd index 2a72980..27c9450 100644 --- a/levels/game_shell.gd +++ b/levels/game_shell.gd @@ -4,6 +4,8 @@ extends Node3D ## spawners, lighting, colliders) into LevelRoot. Switching levels frees the whole ## previous module first, so no old mesh or collider can survive into the next fight. +const PhysicsLayers = preload("res://physics_layers.gd") + @onready var _level_root: Node3D = $LevelRoot @onready var _camera: IsoCamera = $Player/Camera3D @@ -25,4 +27,16 @@ func load_active_level() -> void: push_warning("game_shell: active level has no level_scene") return _camera.set_framing_scale(level.camera_zoom) - _level_root.add_child(level.level_scene.instantiate()) + var module := level.level_scene.instantiate() + _tag_environment_for_corpses(module) + _level_root.add_child(module) + + +## Ground and walls stay on WORLD so the bull and live matadors collide with them; here +## we add CORPSE too. A killed matador's ragdoll is masked to CORPSE alone, so it rests +## on the arena while the bull — which only collides with WORLD — passes through the body +## instead of spazzing out on it. Done at load so it also reaches colliders baked into +## the instanced GLB arenas, not just the level module's own floor box. +func _tag_environment_for_corpses(module: Node) -> void: + for body: StaticBody3D in module.find_children("*", "StaticBody3D", true, false): + body.collision_layer |= PhysicsLayers.CORPSE diff --git a/matador_ragdoll.gd b/matador_ragdoll.gd index 6770be7..6b7a105 100644 --- a/matador_ragdoll.gd +++ b/matador_ragdoll.gd @@ -4,6 +4,8 @@ extends RefCounted ## limited swing/twist (DP-tunable) so the corpse keeps its silhouette instead of ## folding into a flat "deflated" pile; the cape stays free (PIN) so it drapes. +const PhysicsLayers = preload("res://physics_layers.gd") + # [bone, radius] → sphere collider; [bone, radius, height] → capsule. const _BONES: Array = [ ["matador", 0.18], @@ -53,10 +55,15 @@ static func build(skeleton: Skeleton3D) -> PhysicalBoneSimulator3D: pb.bone_name = bname pb.mass = 0.4 pb.linear_damp = 0.1 - pb.collision_layer = 1 - pb.collision_mask = 1 + # The ragdoll only simulates once the matador is dead, so it lives on the CORPSE + # layer and masks to CORPSE alone: it rests on the ground/walls (which also carry + # CORPSE) but the bull — which collides only with WORLD — passes straight through + # the bodies instead of tripping over them. + pb.collision_layer = PhysicsLayers.CORPSE + pb.collision_mask = PhysicsLayers.CORPSE if bname.begins_with("Bone"): - # Cape: floppy cloth — free swing, light, draggy, one-way collision. + # Cape: floppy cloth — free swing, light, draggy, one-way collision (layer 0 + # so nothing collides with it; it still drapes on the CORPSE-masked ground). pb.joint_type = PhysicalBone3D.JOINT_TYPE_PIN pb.mass = 0.15 pb.linear_damp = 0.5 diff --git a/physics_layers.gd b/physics_layers.gd new file mode 100644 index 0000000..ea74ba3 --- /dev/null +++ b/physics_layers.gd @@ -0,0 +1,11 @@ +## Central registry of the 3D physics collision-layer bits. These mirror the +## layer_names in project.godot so the editor's layer picker reads the same words. +## +## The bull only collides with WORLD, so a killed matador is lifted off WORLD onto +## CORPSE alone (see matador_ragdoll.gd). The ground and walls carry WORLD | CORPSE +## (tagged at level load in game_shell.gd), so the ragdoll still rests on the arena +## while the bull passes through the bodies instead of tripping over them. + +const WORLD: int = 1 # layer 1 — environment + live actors (bull, matadors, spears) +const BULL: int = 2 # layer 2 — the bull's own body +const CORPSE: int = 4 # layer 3 — ragdolled matadors; ground/walls also carry this diff --git a/physics_layers.gd.uid b/physics_layers.gd.uid new file mode 100644 index 0000000..4dd4fda --- /dev/null +++ b/physics_layers.gd.uid @@ -0,0 +1 @@ +uid://d01o2ul83waw5 diff --git a/project.godot b/project.godot index c721e03..0e8157b 100644 --- a/project.godot +++ b/project.godot @@ -118,6 +118,12 @@ ability_roll={ pointing/emulate_touch_from_mouse=true +[layer_names] + +3d_physics/layer_1="world" +3d_physics/layer_2="bull" +3d_physics/layer_3="corpse" + [physics] 3d/physics_engine="Jolt Physics"