diff options
author | dusoleil <howcansocksbereal@gmail.com> | 2022-09-14 10:34:36 -0400 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2022-09-15 08:48:02 -0400 |
commit | 79b829e35ae65e3c046e7081aeb2557242e93d24 (patch) | |
tree | 913005f3e1d8cb10e03178822df5dd0f76f13974 /Float.gd | |
parent | f286df6645f130efe6f3edb34036ec7f5b3d777a (diff) | |
download | godot_wildjam_49-79b829e35ae65e3c046e7081aeb2557242e93d24.tar.gz godot_wildjam_49-79b829e35ae65e3c046e7081aeb2557242e93d24.zip |
Small correction to buoyancy physics
Diffstat (limited to 'Float.gd')
-rw-r--r-- | Float.gd | 12 |
1 files changed, 5 insertions, 7 deletions
@@ -1,17 +1,15 @@ extends Spatial -var linear_drag = 0.99 -var angular_drag = 0.5 +onready var inv_gravity = -ProjectSettings.get_setting("physics/3d/default_gravity_vector") * ProjectSettings.get_setting("physics/3d/default_gravity") func _physics_process(_delta): var parent = get_parent() var water = get_node("/root/Main/Water/MeshInstance") - #self.global_transform.origin.y = water.height(self.global_transform.origin) var height = self.global_transform.origin.y var wave_height = water.height(self.global_transform.origin) if height < wave_height: var pos = self.global_transform.origin-parent.global_transform.origin - var buoyancy = clamp(wave_height-height,0.0,1.0) - parent.add_force(Vector3.UP*9.8*buoyancy, pos) - parent.add_central_force(buoyancy * -parent.linear_velocity * linear_drag) - parent.add_torque(buoyancy * -parent.angular_velocity * angular_drag) + #buoyancy force is weight of the displaced water + #we can estimate it by how deep we are in the water + var buoyancy = inv_gravity * clamp(wave_height-height,0.0,1.0) + parent.add_force(buoyancy, pos) |