blob: 4cf7ddadf04a365ec3dcc792e784153e9dd39207 (
plain) (
tree)
|
|
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/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)
|