diff options
Diffstat (limited to '')
-rw-r--r-- | Float.gd | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Float.gd b/Float.gd new file mode 100644 index 0000000..7855bea --- /dev/null +++ b/Float.gd @@ -0,0 +1,17 @@ +extends Spatial + +var linear_drag = 0.99 +var angular_drag = 0.5 + +func _physics_process(_delta): + var parent = get_parent() + var water = get_node("/root/Main/Water") + #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) |