Add buoyancy force debug

This commit is contained in:
Lucas 2025-07-03 12:26:29 +02:00
parent bfb2b27d2a
commit 8280fdf4cd
No known key found for this signature in database
2 changed files with 20 additions and 2 deletions

View file

@ -24,6 +24,8 @@ size = Vector3(0.1, 2.5, 0.1)
[node name="Boat" type="RigidBody3D"]
mass = 50.0
editor_description = "Base class for a floating boat"
can_sleep = false
linear_damp_mode = 1
linear_damp = 0.8
angular_damp = 34.351

View file

@ -18,6 +18,7 @@ var currentdepth:float
var sphere_preview:MeshInstance3D
@onready var debug_sphere:SphereMesh = SphereMesh.new()
@onready var debug_label:Label3D = Label3D.new()
@export_category("Wave")
var noise: Image
@ -47,6 +48,16 @@ func _ready() -> void:
debug_sphere.radius = 0.1
debug_sphere.height = 0.2
sphere_preview.mesh = debug_sphere
if debug:
debug_label.billboard = 1
debug_label.outline_render_priority = 98
debug_label.render_priority = 99
debug_label.pixel_size = 0.005
debug_label.horizontal_alignment = 0
debug_label.no_depth_test = true
debug_label.font_size = 50
add_child(debug_label)
func _physics_process(_delta: float) -> void:
if not Engine.is_editor_hint():
@ -56,9 +67,14 @@ func _physics_process(_delta: float) -> void:
var float_force = parentRigid.mass * float_strength
#parentRigid.gravity_scale = 0.3
#parentRigid.angular_damp = 15.0
parentRigid.apply_force(Vector3.UP * clamp(gravity * depth * float_force,-max_float_force,max_float_force) ,global_position-parentRigid.global_position)
var applied_force : Vector3 = Vector3.UP * clamp(gravity * depth * float_force,-max_float_force,max_float_force)
parentRigid.apply_force(applied_force,global_position-parentRigid.global_position)
if debug:
print(str(self)+" is applying a force of "+str(Vector3.UP * clamp(gravity * depth * float_force,-max_float_force,max_float_force) ,global_position-parentRigid.global_position)+"to "+str(parentRigid))
#print(str(self)+" is applying a force of "+str(applied_force)+" at "+str(global_position-parentRigid.global_position)+" to "+str(parentRigid))
debug_label.text = str(snappedf(applied_force.y,0.01))
debug_label.global_position = global_position
debug_label.global_position.y = get_wave_height(global_position,Oceantime)+0.3
func _process(_delta: float) -> void:
if OceanNode != null: