something like water
This commit is contained in:
@@ -45,11 +45,11 @@ public class WaterShapeController : MonoBehaviour
|
||||
float xPosition=waterTopLeftCorner.x+(spacingPerWawe * count);
|
||||
Vector3 wavePoint=new Vector3(xPosition,waterTopLeftCorner.y,waterTopLeftCorner.z);
|
||||
waterSpline.InsertPointAt(index, wavePoint );
|
||||
waterSpline.SetHeight(index, 0.1f);
|
||||
waterSpline.SetHeight(index, 0f);
|
||||
waterSpline.SetCorner(index, false);
|
||||
}
|
||||
CreateSprings(waterSpline);
|
||||
Splash(2, 1);
|
||||
Splash(2, 0.1f);
|
||||
}
|
||||
|
||||
private void CreateSprings(Spline waterSpline)
|
||||
@@ -58,8 +58,12 @@ public class WaterShapeController : MonoBehaviour
|
||||
for(int idx=0;idx<_wavesCount+1; idx++)
|
||||
{
|
||||
int index = idx + 1;
|
||||
|
||||
Smoothen(waterSpline, index);
|
||||
|
||||
GameObject wavePoint = Instantiate(wavePointPref, _wavePoints.transform, false);
|
||||
wavePoint.transform.localPosition = waterSpline.GetPosition(index);
|
||||
|
||||
wavePoint.transform.position = waterSpline.GetPosition(index);
|
||||
WaterSpring waterSpring=wavePoint.GetComponent<WaterSpring>();
|
||||
waterSpring.Init(_spriteShapeController);
|
||||
_springs.Add( waterSpring );
|
||||
@@ -67,6 +71,33 @@ public class WaterShapeController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private void Smoothen(Spline waterSpline, int index)
|
||||
{
|
||||
Vector3 position = waterSpline.GetPosition(index);
|
||||
Vector3 positionPrev = position;
|
||||
Vector3 positionNext = position;
|
||||
if (index > 1)
|
||||
{
|
||||
positionPrev = waterSpline.GetPosition(index - 1);
|
||||
}
|
||||
if (index - 1 <= _wavesCount)
|
||||
{
|
||||
positionNext = waterSpline.GetPosition(index + 1);
|
||||
}
|
||||
|
||||
Vector3 forward = gameObject.transform.forward;
|
||||
|
||||
float scale = Mathf.Min((positionNext - position).magnitude, (positionPrev - position).magnitude) * 0.33f;
|
||||
|
||||
Vector3 leftTangent = (positionPrev - position).normalized * scale;
|
||||
Vector3 rightTangent = (positionNext - position).normalized * scale;
|
||||
|
||||
SplineUtility.CalculateTangents(position, positionPrev, positionNext, forward, scale, out rightTangent, out leftTangent);
|
||||
|
||||
waterSpline.SetLeftTangent(index, leftTangent);
|
||||
waterSpline.SetRightTangent(index, rightTangent);
|
||||
}
|
||||
|
||||
private void UpdateSprings()
|
||||
{
|
||||
int springsCount = _springs.Count;
|
||||
@@ -94,7 +125,7 @@ public class WaterShapeController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// On Enable for example purposes
|
||||
//On Enable for example purposes
|
||||
void OnEnable()
|
||||
{
|
||||
StartCoroutine(CreateWaves());
|
||||
@@ -124,6 +155,7 @@ public class WaterShapeController : MonoBehaviour
|
||||
foreach (WaterSpring spring in _springs)
|
||||
{
|
||||
spring.WaveSpringUpdate(_springStiffness, _dampening);
|
||||
spring.WavePointUpdate();
|
||||
}
|
||||
UpdateSprings();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class WaterSpring : MonoBehaviour
|
||||
Height = transform.localPosition.y;
|
||||
}
|
||||
|
||||
public void WavePointUpdate(int level)
|
||||
public void WavePointUpdate()
|
||||
{
|
||||
if (_spriteShapeController != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user