From fbbc58ae83428781c5429517a40a9ce5015f0c5e Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Wed, 20 Nov 2024 22:04:35 -0700 Subject: [PATCH] Ball reports most upward normal --- levels/debug_level/debug_level.tscn | 8 ++++---- src/equipment/balls/physics_ball/game_ball.gd | 10 +++++++++- src/equipment/balls/physics_ball/physics_ball.tscn | 2 +- src/ui/shot_hud/ball_selector/ball_selector.tscn | 14 +++++++++----- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/levels/debug_level/debug_level.tscn b/levels/debug_level/debug_level.tscn index 5693506..3923a7b 100644 --- a/levels/debug_level/debug_level.tscn +++ b/levels/debug_level/debug_level.tscn @@ -341,16 +341,16 @@ transform = Transform3D(-0.734269, 0.305072, -0.606448, 0, 0.893336, 0.44939, 0. transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 129.404, -9.53674e-07, 309.4) [node name="ConcreteBuilding1" parent="CityBuildings" instance=ExtResource("10_lf15j")] -transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, 0, 0) +transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, 0, -0.01, 0) [node name="KanaSignboard" parent="CityBuildings/ConcreteBuilding1" instance=ExtResource("11_evxup")] transform = Transform3D(-8.74228e-08, 0, -2, 0, 2, 0, 2, 0, -8.74228e-08, 10.8, 12, 7) [node name="ConcreteBuilding2" parent="CityBuildings" instance=ExtResource("10_lf15j")] -transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, 0, 20) +transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, -0.01, 20) [node name="ConcreteBuilding3" parent="CityBuildings" instance=ExtResource("10_lf15j")] -transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, 0, 40) +transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0, -0.01, 40) [node name="PalmTree" parent="CityBuildings" instance=ExtResource("12_sswxf")] transform = Transform3D(-0.69799, 0, -0.716107, 0, 1, 0, 0.716107, 0, -0.69799, 11.468, 0, -12.468) @@ -370,7 +370,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 137.181, -20, -7.285) curve = SubResource("Curve3D_5n8tb") [node name="ConcreteBuilding1" parent="MountainCurve" instance=ExtResource("10_lf15j")] -transform = Transform3D(-0.0979477, 0, 0.995192, 0, 1, 0, -0.995192, 0, -0.0979477, -10.074, 0, -32.347) +transform = Transform3D(-0.0979477, 0, 0.995192, 0, 1, 0, -0.995192, 0, -0.0979477, -10.074, -0.01, -32.347) [node name="GuardRail" parent="MountainCurve" instance=ExtResource("16_xtxyj")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 70.2122, 0, 116.269) diff --git a/src/equipment/balls/physics_ball/game_ball.gd b/src/equipment/balls/physics_ball/game_ball.gd index aaec4f7..c01552b 100644 --- a/src/equipment/balls/physics_ball/game_ball.gd +++ b/src/equipment/balls/physics_ball/game_ball.gd @@ -68,7 +68,15 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void: var damping := air_damping if state.get_contact_count(): - _last_contact_normal = state.get_contact_local_normal(0) + # We want the contact normal which minimizes the angle to the up vector + var min_dot := -1.0 + for i: int in range(state.get_contact_count()): + var norm := state.get_contact_local_normal(i) + var dot := norm.dot(Vector3.UP) + if dot > min_dot: + min_dot = dot + _last_contact_normal = norm + damping = _total_terrain_angular_damping() if damping <= TERRAIN_DAMPING_EPSILON: damping = rough_damping diff --git a/src/equipment/balls/physics_ball/physics_ball.tscn b/src/equipment/balls/physics_ball/physics_ball.tscn index d3e537b..2f25e3e 100644 --- a/src/equipment/balls/physics_ball/physics_ball.tscn +++ b/src/equipment/balls/physics_ball/physics_ball.tscn @@ -63,7 +63,7 @@ physics_material_override = ExtResource("1_l23pw") freeze = true continuous_cd = true contact_monitor = true -max_contacts_reported = 1 +max_contacts_reported = 3 linear_damp_mode = 1 angular_damp_mode = 1 angular_damp = 8.0 diff --git a/src/ui/shot_hud/ball_selector/ball_selector.tscn b/src/ui/shot_hud/ball_selector/ball_selector.tscn index d8336f8..f961201 100644 --- a/src/ui/shot_hud/ball_selector/ball_selector.tscn +++ b/src/ui/shot_hud/ball_selector/ball_selector.tscn @@ -44,11 +44,15 @@ texture = SubResource("GradientTexture2D_tm61r") unique_name_in_owner = true custom_minimum_size = Vector2(120, 0) layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_top = 50.0 -offset_bottom = 50.0 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -120.0 +offset_top = 18.0 +offset_right = 120.0 +offset_bottom = 146.0 grow_horizontal = 2 grow_vertical = 2 theme_override_constants/separation = 5