Files
CosmicClash/Game/objects/ball.tscn
T
Josh Creek c75e142c8a perf(physics): name and assign collision layers
Adds a [layer_names] section to project.godot (Ships/Ball/Arena/
GoalSensor) and sets collision_layer/collision_mask on the 4 physics
body roots (Ship, Ball, Goal Area3D, ArenaBoundary StaticBody3D),
which previously all sat on the default layer 1 / mask 1 so every
body broadphase-tested against every other.

Ships collide with ships/ball/arena but no longer test against the
goal sensor; the goal's mask (Ball only) is the physics-level fix for
what goal.gd's is_in_group("ball") check was doing defensively in
code (left in place, now a no-op guard). ArenaBoundary's runtime-
generated CollisionShape3D children inherit layer/mask from the
StaticBody3D root automatically.

Verified live via godot-mcp under Jolt Physics: ship-vs-ship and
ship-vs-ball collisions still transfer momentum, the ball still
bounces off arena walls, a ball entering a goal still fires
goal_scored (score updates / HUD reset), and a ship teleported into a
goal recess produces zero overlapping bodies on the goal Area3D (was
reachable before, physics-level fix confirmed, not just the code
guard). Headless smoke test (free_play.tscn) is clean.
2026-08-04 18:32:54 +01:00

31 lines
965 B
Plaintext

[gd_scene load_steps=5 format=3 uid="uid://27u3tdc5yqnl"]
[ext_resource type="ArrayMesh" path="res://assets/models/ball.res" id="1_ball"]
[ext_resource type="Script" path="res://scripts/ball.gd" id="2_ball"]
[sub_resource type="SphereShape3D" id="SphereShape3D_c5p07"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_ball"]
bounce = 0.5
friction = 0.4
[node name="Ball" type="RigidBody3D" groups=["ball"]]
collision_layer = 2
collision_mask = 13
mass = 3
physics_material_override = SubResource("PhysicsMaterial_ball")
continuous_cd = true
inertia = Vector3(3, 3, 3)
gravity_scale = 0.8
linear_damp = 0.1
angular_damp = 0.1
script = ExtResource("2_ball")
metadata/_edit_group_ = true
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("SphereShape3D_c5p07")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0)
mesh = ExtResource("1_ball")