generated from krampus/template-godot4
	Ball damping gets scaled up after rolling for a while
This commit is contained in:
		
							parent
							
								
									3d54994e34
								
							
						
					
					
						commit
						d268391eb8
					
				| @ -22,9 +22,20 @@ const MAGNUS_SQ_EPSILON := 1e-3 | |||||||
| ## Material physics configuration for this ball. | ## Material physics configuration for this ball. | ||||||
| @export var terrain_physics: TerrainPhysics | @export var terrain_physics: TerrainPhysics | ||||||
| 
 | 
 | ||||||
| ## Coefficient of the linear curve that determines the minimum speed at | ## Coefficient of the roll damping quadratic curve. | ||||||
| ## a given point in surface time below which the ball will be frozen. | ## This applies progressively greater damping after the ball rolls for a period of time. | ||||||
| @export var surface_cull_coefficient: float = 0.2 | @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 fluid_density := 1.225 | ||||||
| #@export var lift_coefficient := 0.05 | #@export var lift_coefficient := 0.05 | ||||||
| @ -137,10 +148,6 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void: | |||||||
| 				primary_body = state.get_contact_collider_object(i) | 				primary_body = state.get_contact_collider_object(i) | ||||||
| 
 | 
 | ||||||
| 		_surface_terrain = Terrain.from_collision(global_position, primary_body) | 		_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: | 	else: | ||||||
| 		# Ball is in the air | 		# Ball is in the air | ||||||
| 		_surface_terrain = Terrain.Type.NONE | 		_surface_terrain = Terrain.Type.NONE | ||||||
| @ -150,6 +157,13 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void: | |||||||
| 	angular_damp = params.angular_damp | 	angular_damp = params.angular_damp | ||||||
| 	linear_damp = params.linear_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: | func _physics_process(delta: float) -> void: | ||||||
| 	# Simulate magnus effect | 	# Simulate magnus effect | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user