summaryrefslogtreecommitdiffstats
path: root/Water.gd
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2022-09-12 20:45:03 -0400
committerdusoleil <howcansocksbereal@gmail.com>2022-09-12 20:45:03 -0400
commit99a70a8677f8d14749bdcd374f1631cd9cbbd3df (patch)
tree9d3cc5334ceb4e698009449c070bec3b4850629e /Water.gd
parent5dbc9c05c1ebd33e37315c096d2c9e1c6b96a8f2 (diff)
downloadgame_jam49-99a70a8677f8d14749bdcd374f1631cd9cbbd3df.tar.gz
game_jam49-99a70a8677f8d14749bdcd374f1631cd9cbbd3df.zip
Add buoyancy simulation to water and floaties on the raft
Diffstat (limited to '')
-rw-r--r--Water.gd32
1 files changed, 32 insertions, 0 deletions
diff --git a/Water.gd b/Water.gd
index f9463e4..da7666c 100644
--- a/Water.gd
+++ b/Water.gd
@@ -78,4 +78,36 @@ func _set_time(val):
func _physics_process(delta):
self._time += delta
+ #self._time = 0.0
+func gertsner_wave(pos, idx):
+ if idx >= waves.size(): return 0.0
+ var wave = waves[idx]
+ var k = wave._k
+ var a = wave._a
+ var t = wave._t
+
+ var d = wave.direction.normalized()
+ var f = k * (d.dot(Vector2(pos.x,pos.z)) - t)
+
+ var tmp = a * cos(f)
+ var new_pos = Vector3(d.x * tmp, a * sin(f), d.y * tmp)
+
+ return new_pos
+
+func sample_wave(pos):
+ var new_pos = Vector3(pos.x,0,pos.z)
+ for idx in waves.size():
+ new_pos += gertsner_wave(pos, idx)
+ return new_pos
+
+func height(pos):
+ var old_pos = pos
+ var y = old_pos.y
+ for _i in range(2):
+ var new_pos = sample_wave(old_pos)
+ y = new_pos.y
+ new_pos = old_pos - (new_pos - old_pos)
+ old_pos = new_pos
+ y += self.global_transform.origin.y
+ return y