summaryrefslogtreecommitdiffstats
path: root/Float.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Float.gd')
-rw-r--r--Float.gd12
1 files changed, 5 insertions, 7 deletions
diff --git a/Float.gd b/Float.gd
index 4cf7dda..37297e4 100644
--- a/Float.gd
+++ b/Float.gd
@@ -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)