public void FixedUpdate() { if (!this || !this.enabled || Disable) { return; } #if UNITY_EDITOR if (!EnableInEditor && Application.isPlaying == false) { return; } #endif if (autoFind) { waterObject = WaterObject.Find(this.transform.position, false); } if (!waterObject || !waterObject.material) { return; } m_waterLevel = waterObject && waterLevelSource == WaterLevelSource.WaterObject? waterObject.transform.position.y : waterLevel; normal = Vector3.up; height = 0f; if (samples.Count == 0) { height = Buoyancy.SampleWaves(this.transform.position, waterObject.material, m_waterLevel - heightOffset, rollAmount, dynamicMaterial, out normal); } else { Vector3 avgNormal = Vector3.zero; for (int i = 0; i < samples.Count; i++) { height += Buoyancy.SampleWaves(ConvertToWorldSpace(samples[i]), waterObject.material, m_waterLevel - heightOffset, rollAmount, dynamicMaterial, out normal); avgNormal += normal; } height /= samples.Count; normal = (avgNormal / samples.Count).normalized; } ApplyTransform(); }
/// <summary> /// Checks if the position is below the maximum possible wave height. Can be used as a fast broad-phase check, before actually using the more expensive SampleWaves function /// </summary> /// <param name="position"></param> public bool CanTouch(Vector3 position) { return(Buoyancy.CanTouchWater(position, this)); }