Skip to content

Commit b3e6bdf

Browse files
committed
Major fix for ball bouncing randomly.
It turns out that balls were frequently bouncing off the 'shadow' animatable body of the other ball, or in some cases even themselves, because the animatable body was invisible but its collision sphere was still active. This would look like a ball randomly bouncing off to nowhere, but it can be seen and reproduced clearly if debug collision shapes are turned on. Disabled the ball objects when not in use.
1 parent c8570dd commit b3e6bdf

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

scenes/ball.gd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,20 @@ var detached : bool:
8383
rigid_body.force_new_linear_velocity(lin_vel)
8484
rigid_body.force_new_angular_velocity(controller_average_angular_velocity)
8585
rigid_body.freeze = false
86+
87+
# Ensure only the rigid body has collisions enabled.
88+
rigid_body.process_mode = Node.PROCESS_MODE_INHERIT
89+
animatable_body.process_mode = Node.PROCESS_MODE_DISABLED
8690
else:
8791
visual.reparent(animatable_body, false)
8892
rigid_body.freeze = true
8993
# Hit ground can be a long rolling sound, so stop it.
9094
snd_hit_ground.stop()
9195

96+
# Ensure only the animatable body has collisions enabled.
97+
rigid_body.process_mode = Node.PROCESS_MODE_DISABLED
98+
animatable_body.process_mode = Node.PROCESS_MODE_INHERIT
99+
92100
## Z rotation to apply to the visual mesh.
93101
@export_range(-180, 180, 1, 'radians_as_degrees') var z_rotate : float = 0.0:
94102
set(value):

scenes/baseball.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ transform = Transform3D(0.065113954, 0, 0, 0, 0.065113954, 0, 0, 0, 0.065113954,
5151
shape = SubResource("SphereShape3D_abd54")
5252

5353
[node name="RigidBody" type="RigidBody3D" parent="."]
54+
process_mode = 4
5455
collision_layer = 4
5556
collision_mask = 94
5657
mass = 0.5

0 commit comments

Comments
 (0)