Help me resolve the issue about SmoothStep
I want to make the ‘radius’ 1st go form 20 to -1, after that from -1 to 5 and after from 5 to 0.
So I tried to make a code with triggers and coroutines, but I don’t get it how to make it work properly
Because I think the time goes the same in every SmoothStep.
IEnumerator BeHole()
{
if (check1 == false)
{
radius = Mathf.SmoothStep (20, -1, Time.time / 3);
}
yield return null;
}
}
IEnumerator BeHole( float transitionDuration, params float radiuses )
{
float inverseTransitionDuration = 1f / transitionDuration ;
radius = radiuses[0];
yield return null;
for ( int index = 0 ; index < radiuses.Length - 1 ; ++index )
{
for ( float t = Time.deltaTime ; t < transitionDuration ; t = Mathf.Min( t + Time.deltaTime, transitionDuration ) )
{
radius = Mathf.SmoothStep (radiuses[index], radiuses[index + 1], t * inverseTransitionDuration );
yield return null;
}
radius = radiuses[index + 1];
yield return null;
}
}
And you call it as follow ONLY ONCE (not each frame)
// The 1st argument is the time needed to go from 20 to -1
StartCoroutine( BeHole( 1, 20f, -1f, 5f, 0f ) ) ;
// OR
// StartCoroutine( BeHole( 1, new float[]{ 20f, -1f, 5f, 0f } ) ) ;