Apply linear damping on impact instead of changing bounce

This commit is contained in:
Rob Kelly 2025-01-09 13:53:08 -07:00
parent cf185592d6
commit 2b4495bbc9
4 changed files with 29 additions and 28 deletions

View File

@ -133,13 +133,14 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
_surface_time_s = 0.0 _surface_time_s = 0.0
# TODO something's fucky here... I think this gets called once after the ball sleeps # TODO something's fucky here... I think this gets called once after the ball sleeps
if state.get_contact_count(): var contacts := state.get_contact_count()
if contacts:
# Ball is in contact with a surface # Ball is in contact with a surface
# We want the contact normal which minimizes the angle to the up vector # We want the contact normal which minimizes the angle to the up vector
var min_dot := -1.0 var min_dot := -2.0
var primary_body: Node var primary_body: Node
for i: int in range(state.get_contact_count()): for i: int in range(contacts):
var norm := state.get_contact_local_normal(i) var norm := state.get_contact_local_normal(i)
var dot := norm.dot(Vector3.UP) var dot := norm.dot(Vector3.UP)
if dot > min_dot: if dot > min_dot:
@ -175,8 +176,6 @@ func _physics_process(delta: float) -> void:
_shot_time_s += delta _shot_time_s += delta
_surface_time_s += delta _surface_time_s += delta
physics_material_override.bounce = terrain_physics.get_params(_surface_terrain).bounce
func enter_zone(zone: BallZone) -> void: func enter_zone(zone: BallZone) -> void:
_zones.push_back(zone) _zones.push_back(zone)
@ -225,6 +224,8 @@ func _on_collision(body: Node) -> void:
sfx.play_sfx(terrain) sfx.play_sfx(terrain)
effects.play_effect(terrain) effects.play_effect(terrain)
linear_velocity *= clampf(1 - terrain_physics.get_params(terrain).impact_damp, 0, 1)
func _fire_sleep_signal() -> void: func _fire_sleep_signal() -> void:
sleeping = true sleeping = true

View File

@ -5,63 +5,63 @@
[sub_resource type="Resource" id="Resource_casfi"] [sub_resource type="Resource" id="Resource_casfi"]
script = ExtResource("1_45pis") script = ExtResource("1_45pis")
linear_damp = 1.15 linear_damp = 1.05
angular_damp = 3.0 angular_damp = 3.0
bounce = 0.9 impact_damp = 0.05
[sub_resource type="Resource" id="Resource_3k63c"] [sub_resource type="Resource" id="Resource_3k63c"]
script = ExtResource("1_45pis") script = ExtResource("1_45pis")
linear_damp = 0.0 linear_damp = 0.0
angular_damp = 0.0 angular_damp = 0.0
bounce = 0.5 impact_damp = 0.0
[sub_resource type="Resource" id="Resource_xf73q"] [sub_resource type="Resource" id="Resource_xf73q"]
script = ExtResource("1_45pis") script = ExtResource("1_45pis")
linear_damp = 4.4 linear_damp = 2.8
angular_damp = 4.0 angular_damp = 4.0
bounce = 0.4 impact_damp = 0.3
[sub_resource type="Resource" id="Resource_nhn3l"] [sub_resource type="Resource" id="Resource_nhn3l"]
script = ExtResource("1_45pis") script = ExtResource("1_45pis")
linear_damp = 0.86 linear_damp = 0.86
angular_damp = 1.0 angular_damp = 1.0
bounce = 0.9 impact_damp = 0.0
[sub_resource type="Resource" id="Resource_m3wjo"] [sub_resource type="Resource" id="Resource_m3wjo"]
script = ExtResource("1_45pis") script = ExtResource("1_45pis")
linear_damp = 2.3 linear_damp = 1.25
angular_damp = 4.0 angular_damp = 4.0
bounce = 0.4 impact_damp = 0.3
[sub_resource type="Resource" id="Resource_h4rld"] [sub_resource type="Resource" id="Resource_h4rld"]
script = ExtResource("1_45pis") script = ExtResource("1_45pis")
linear_damp = 1.62 linear_damp = 1.62
angular_damp = 1.0 angular_damp = 1.0
bounce = 0.9 impact_damp = 0.0
[sub_resource type="Resource" id="Resource_j6lib"] [sub_resource type="Resource" id="Resource_j6lib"]
script = ExtResource("1_45pis") script = ExtResource("1_45pis")
linear_damp = 4.7 linear_damp = 4.0
angular_damp = 2.0 angular_damp = 2.0
bounce = 0.6 impact_damp = 0.15
[sub_resource type="Resource" id="Resource_7f7ql"] [sub_resource type="Resource" id="Resource_7f7ql"]
script = ExtResource("1_45pis") script = ExtResource("1_45pis")
linear_damp = 7.6 linear_damp = 3.0
angular_damp = 4.0 angular_damp = 8.0
bounce = 0.3 impact_damp = 0.5
[sub_resource type="Resource" id="Resource_pusmf"] [sub_resource type="Resource" id="Resource_pusmf"]
script = ExtResource("1_45pis") script = ExtResource("1_45pis")
linear_damp = 12.0 linear_damp = 4.0
angular_damp = 32.0 angular_damp = 4.0
bounce = 0.0 impact_damp = 0.7
[sub_resource type="Resource" id="Resource_edkxb"] [sub_resource type="Resource" id="Resource_edkxb"]
script = ExtResource("1_45pis") script = ExtResource("1_45pis")
linear_damp = 1.55 linear_damp = 1.25
angular_damp = 1.3 angular_damp = 1.3
bounce = 0.8 impact_damp = 0.15
[resource] [resource]
script = ExtResource("2_yuehx") script = ExtResource("2_yuehx")

View File

@ -16,7 +16,7 @@
[ext_resource type="PackedScene" uid="uid://cm4bb3lg4mfd2" path="res://src/world/effects/splash/splash_effect.tscn" id="12_qlrvx"] [ext_resource type="PackedScene" uid="uid://cm4bb3lg4mfd2" path="res://src/world/effects/splash/splash_effect.tscn" id="12_qlrvx"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_u134x"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_u134x"]
bounce = 0.4 bounce = 0.8
[sub_resource type="SphereMesh" id="SphereMesh_y0d13"] [sub_resource type="SphereMesh" id="SphereMesh_y0d13"]
material = ExtResource("3_rc7m1") material = ExtResource("3_rc7m1")

View File

@ -5,6 +5,6 @@ class_name TerrainParameters extends Resource
@export var linear_damp := 0.0 @export var linear_damp := 0.0
## Angular damping applied while in contact with the terrain surface. ## Angular damping applied while in contact with the terrain surface.
@export var angular_damp := 0.0 @export var angular_damp := 0.0
## Linear damping applied the frame the ball makes contact with the surface.
## Physical bounciness of the terrain. Use this instead of the physics material override. ## This is applied in addition `linear_damp`.
@export var bounce := 0.0 @export var impact_damp := 0.0