From 6e34f236cab279f7cf4e147bf417b0b564dfd1b5 Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Thu, 21 Nov 2024 18:54:38 -0700 Subject: [PATCH] Balls get explosive separation force on impact --- levels/debug_level/debug_level.tscn | 24 +----------------------- src/player/shot_setup/shot_setup.gd | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/levels/debug_level/debug_level.tscn b/levels/debug_level/debug_level.tscn index 3923a7b..edf1bf9 100644 --- a/levels/debug_level/debug_level.tscn +++ b/levels/debug_level/debug_level.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=55 format=3 uid="uid://bm2o3mex10v11"] +[gd_scene load_steps=51 format=3 uid="uid://bm2o3mex10v11"] [ext_resource type="Texture2D" path="res://assets/textures/grass_fairway/grass_fairway_albedo.dds" id="2_e4m27"] [ext_resource type="Texture2D" path="res://assets/textures/grass_rough/grass_rough_albedo.dds" id="4_p0awb"] @@ -17,7 +17,6 @@ [ext_resource type="PackedScene" uid="uid://di7aql54lksn7" path="res://src/props/scenery/trees/palm_tree/palm_tree.tscn" id="12_sswxf"] [ext_resource type="PackedScene" uid="uid://c7l58wuuahn7w" path="res://src/props/flag/flag.tscn" id="13_6jtao"] [ext_resource type="PackedScene" uid="uid://cl0goj38u7r72" path="res://src/props/scenery/beach/sailboat.tscn" id="14_6reiy"] -[ext_resource type="Texture2D" uid="uid://dj60e8ri2fco" path="res://assets/models/scenery/city/concrete_building_1/concrete_building_1.png" id="14_y7s2h"] [ext_resource type="Texture2D" uid="uid://du3vk5nnksohs" path="res://assets/sprites/particles/sparkle.png" id="16_2m5yu"] [ext_resource type="PackedScene" uid="uid://nqar1qcun8ax" path="res://src/props/scenery/highway/guard_rail/guard_rail.tscn" id="16_xtxyj"] [ext_resource type="PackedScene" uid="uid://d0tcr6uijpym5" path="res://src/props/scenery/highway/highway_road.tscn" id="17_amems"] @@ -137,17 +136,6 @@ dof_blur_near_enabled = true dof_blur_near_distance = 1.0 dof_blur_near_transition = 0.5 -[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_5p7vs"] -albedo_texture = ExtResource("14_y7s2h") -uv1_scale = Vector3(300, 800, 1) - -[sub_resource type="BoxMesh" id="BoxMesh_20p1k"] -material = SubResource("StandardMaterial3D_5p7vs") -size = Vector3(300, 1, 800) - -[sub_resource type="BoxShape3D" id="BoxShape3D_g31tw"] -size = Vector3(300, 1, 800) - [sub_resource type="FastNoiseLite" id="FastNoiseLite_mgjj0"] fractal_type = 2 @@ -280,16 +268,6 @@ transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 209.78 depth = 10.0 polygon = PackedVector2Array(-1.47594, 8.77969, -12.788, 19.9447, -17.7778, 31.2864, -19.2001, 41.1398, -19.2001, 55.4081, -16.3465, 66.9813, -15.7123, 75.8594, -14.9196, 82.6765, -12.383, 89.9692, -5.6736, 102.186, 2.88742, 115.027, 9.22891, 125.332, 14.7777, 133.893, 23.4973, 146.417, 35.7046, 159.893, 44.1071, 167.661, 55.8437, 178.18, 64.5632, 185.314, 69.7949, 189.753, 73.7584, 193.082, 80.734, 200.85, 94.5267, 212.899, 106.576, 221.46, 127.915, 233.827, 139.647, 240.802, 170.403, 256.181, 183.721, 262.839, 204.489, 271.717, 216.062, 274.571, 224.465, 279.485, 235.727, 283.429, 246.983, 289.929, 253.958, 290.88, 265.373, 296.27, 275.044, 298.965, 288.995, 299.282, 302.154, 299.599, 330.056, 297.063, 356.532, 289.612, 370.483, 282.636, 382.057, 270.112, 388.081, 259.648, 392.679, 245.221, 395.849, 226.989, 395.863, 185.922, 391.266, 164.52, 381.913, 148.636, 362.889, 133.417, 344.657, 121.051, 327.059, 111.063, 306.291, 103.136, 292.974, 102.66, 277.913, 102.66, 264.913, 105.99, 241.347, 117.315, 222.323, 125.558, 203.457, 127.144, 182.371, 123.973, 157.322, 119.534, 132.908, 107.644, 108.651, 86.0827, 88.8301, 59.386, 82.6471, 48.764, 75.6715, 25.7761, 65.063, 10.562, 56.819, 3.7449, 48.5751, -0.852661, 35.2579, -3.07219, 20.8311, -3.38925, 7.35541, 1.36685) -[node name="DebugTable" type="MeshInstance3D" parent="Course"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 150, 0, -400) -mesh = SubResource("BoxMesh_20p1k") -skeleton = NodePath("../..") - -[node name="StaticBody3D" type="StaticBody3D" parent="Course/DebugTable"] - -[node name="CollisionShape3D" type="CollisionShape3D" parent="Course/DebugTable/StaticBody3D"] -shape = SubResource("BoxShape3D_g31tw") - [node name="WaterTable" type="MeshInstance3D" parent="Course"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0) mesh = SubResource("PlaneMesh_2ywhk") diff --git a/src/player/shot_setup/shot_setup.gd b/src/player/shot_setup/shot_setup.gd index 14a5de0..d6344ec 100644 --- a/src/player/shot_setup/shot_setup.gd +++ b/src/player/shot_setup/shot_setup.gd @@ -41,6 +41,9 @@ const CURVE_INFLUENCE := PI / 8 ## Maximum absolute curve for the "nice shot" animation to play const NICE_THRESHOLD := 0.2 +## Force by which explosions knock the ball away +const EXPLOSIVE_FORCE_FACTOR := 0.12 + ## In Driving Range mode, the ball can be retrieved in the shot phase. @export var driving_range := false @@ -585,11 +588,21 @@ func _on_hitbox_ball_collision(ball: GameBall) -> void: # TODO play animation var damage := ball.get_damage() player.life -= damage - game.viewport.hit_lag_big() + game.viewport.hit_lag_small() game.viewport.screen_shake(damage, 0.4) explosion_animation.play("explode") # TODO kinematic collisions + # Knock other ball away + var explosion_impulse := ( + ( + (ball.global_position - global_position).normalized() * damage + + global_basis.y.normalized() + ) + * EXPLOSIVE_FORCE_FACTOR + ) + ball.apply_central_impulse(explosion_impulse) + ## Create a new instance for the given player. static func create(_player: WorldPlayer) -> ShotSetup: