diff options
author | dusoleil <howcansocksbereal@gmail.com> | 2022-09-12 20:45:03 -0400 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2022-09-12 20:45:03 -0400 |
commit | 99a70a8677f8d14749bdcd374f1631cd9cbbd3df (patch) | |
tree | 9d3cc5334ceb4e698009449c070bec3b4850629e /Float.gd | |
parent | 5dbc9c05c1ebd33e37315c096d2c9e1c6b96a8f2 (diff) | |
download | game_jam49-99a70a8677f8d14749bdcd374f1631cd9cbbd3df.tar.gz game_jam49-99a70a8677f8d14749bdcd374f1631cd9cbbd3df.zip |
Add buoyancy simulation to water and floaties on the raft
Diffstat (limited to 'Float.gd')
-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) |