summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2022-09-22 07:45:09 -0400
committerdusoleil <howcansocksbereal@gmail.com>2022-09-22 07:45:09 -0400
commitf342c55099bbd6af781aab7324340460b6299e98 (patch)
tree84546283b1014312c2e0bc35a964901cb299985b
parentdf3557dc3b04b1fa2f399ea319d8810f37931035 (diff)
downloadgodot_wildjam_49-f342c55099bbd6af781aab7324340460b6299e98.tar.gz
godot_wildjam_49-f342c55099bbd6af781aab7324340460b6299e98.zip
Use the root of the Water scene for the Water API
-rw-r--r--Float.gd2
-rw-r--r--water/Water.gd12
-rw-r--r--water/Water.tscn10
3 files changed, 13 insertions, 11 deletions
diff --git a/Float.gd b/Float.gd
index 37297e4..77ffa95 100644
--- a/Float.gd
+++ b/Float.gd
@@ -4,7 +4,7 @@ onready var inv_gravity = -ProjectSettings.get_setting("physics/3d/default_gravi
func _physics_process(_delta):
var parent = get_parent()
- var water = get_node("/root/Main/Water/MeshInstance")
+ var water = get_node("/root/Main/Water")
var height = self.global_transform.origin.y
var wave_height = water.height(self.global_transform.origin)
if height < wave_height:
diff --git a/water/Water.gd b/water/Water.gd
index 99efa74..32f89ca 100644
--- a/water/Water.gd
+++ b/water/Water.gd
@@ -1,4 +1,4 @@
-extends MeshInstance
+extends Spatial
tool
export var wave1_steepness = 0.5 setget _set_wave1_steepness
@@ -13,11 +13,13 @@ export var wave3_steepness = 0.5 setget _set_wave3_steepness
export var wave3_wavelength = 10.0 setget _set_wave3_wavelength
export var wave3_direction = Vector2(1.0,0.0) setget _set_wave3_direction
+onready var water_plane = $"MeshInstance"
+
func _set_wave_prop(idx, prop, val):
if val == null: return
if idx >= waves.size(): return
waves[idx].set(prop,val)
- _update_wave(0)
+ _update_wave(idx)
func _set_wave1_steepness(val):
wave1_steepness = val
@@ -66,13 +68,13 @@ func _wave_to_v3(wave):
return Vector3(wave.steepness,wave._k,wave._a)
func _update_wave(idx):
- var material = self.get_surface_material(0)
+ var material = self.water_plane.get_surface_material(0)
material.set_shader_param("wave" + str(idx+1), _wave_to_v3(waves[idx]))
material.set_shader_param("wave" + str(idx+1) + "_dir", waves[idx].direction)
func _set_time(val):
_time = val
- var material = self.get_surface_material(0)
+ var material = self.water_plane.get_surface_material(0)
for idx in waves.size():
waves[idx]._time = _time
material.set_shader_param("wave" + str(idx+1) + "_t", waves[idx]._t)
@@ -109,5 +111,5 @@ func height(pos):
y = new_pos.y
new_pos = old_pos - (new_pos - old_pos)
old_pos = new_pos
- y += self.global_transform.origin.y
+ y += self.water_plane.global_transform.origin.y
return y
diff --git a/water/Water.tscn b/water/Water.tscn
index 0110acd..6b4c72b 100644
--- a/water/Water.tscn
+++ b/water/Water.tscn
@@ -34,11 +34,6 @@ shader_param/refraction_amount = 0.01
shader_param/noise = SubResource( 21 )
[node name="Water" type="Spatial"]
-
-[node name="MeshInstance" type="MeshInstance" parent="."]
-layers = 2
-mesh = SubResource( 9 )
-material/0 = SubResource( 11 )
script = ExtResource( 2 )
wave1_steepness = 0.25
wave1_wavelength = 60.0
@@ -49,3 +44,8 @@ wave2_direction = Vector2( 1, 0.6 )
wave3_steepness = 0.25
wave3_wavelength = 18.0
wave3_direction = Vector2( 1, 1.3 )
+
+[node name="MeshInstance" type="MeshInstance" parent="."]
+layers = 2
+mesh = SubResource( 9 )
+material/0 = SubResource( 11 )