Ball damping gets scaled up after rolling for a while

This commit is contained in:
Rob Kelly 2025-01-07 21:09:03 -07:00
parent 3d54994e34
commit d268391eb8
1 changed files with 21 additions and 7 deletions

View File

@ -22,9 +22,20 @@ const MAGNUS_SQ_EPSILON := 1e-3
## Material physics configuration for this ball.
@export var terrain_physics: TerrainPhysics
## Coefficient of the linear curve that determines the minimum speed at
## a given point in surface time below which the ball will be frozen.
@export var surface_cull_coefficient: float = 0.2
## Coefficient of the roll damping quadratic curve.
## This applies progressively greater damping after the ball rolls for a period of time.
@export var roll_damping_coefficient := 0.4
## Time in seconds after the ball begins rolling after which roll damping will start to apply.
## This applies progressively greater damping after the ball rolls for a period of time.
@export var roll_damping_delay := 12.0
## Coefficient of the roll cull linear curve.
## The ball be frozen if it rolls with speed under this curve.
@export var roll_cull_coefficient := 0.2
## Time in seconds after the ball begins rolling after which roll culling will start to apply.
@export var roll_cull_delay := 16.0
#@export var fluid_density := 1.225
#@export var lift_coefficient := 0.05
@ -137,10 +148,6 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
primary_body = state.get_contact_collider_object(i)
_surface_terrain = Terrain.from_collision(global_position, primary_body)
var culling_speed_sq := pow(surface_cull_coefficient * _surface_time_s, 2) - 1
if linear_velocity.length_squared() < culling_speed_sq:
_manual_sleep()
else:
# Ball is in the air
_surface_terrain = Terrain.Type.NONE
@ -150,6 +157,13 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
angular_damp = params.angular_damp
linear_damp = params.linear_damp
# Progressively increase linear damping after a delay.
linear_damp += roll_damping_coefficient * pow(maxf(_surface_time_s - roll_damping_delay, 0), 2)
var cull_speed := roll_cull_coefficient * maxf(_surface_time_s - roll_cull_delay, 0)
if linear_velocity.length_squared() < pow(cull_speed, 2):
_manual_sleep()
func _physics_process(delta: float) -> void:
# Simulate magnus effect