private static System.Func <float, float> getInterpolationFunc(INTERPOLATION_TYPE type) { switch (type) { case INTERPOLATION_TYPE.LERP: return(lerp); case INTERPOLATION_TYPE.SMOOTH: return(smoothInterpolation); default: return(smoothInterpolation); } }
public static IEnumerator rotateObject(GameObject go, Vector3 eulerAngles, float duration, INTERPOLATION_TYPE type = INTERPOLATION_TYPE.SMOOTH, int power = 1) //works! { Vector3 startAngles = go.transform.eulerAngles; System.Func <float, float> interpolationFunc = getInterpolationFunc(type); float newValue = 0.0f; float pd = 0; for (float i = 0; i < duration; i += Time.deltaTime) //might be buggy. not tested super much { pd = i / duration; newValue = interpolationFunc(pd); newValue = Mathf.Pow(newValue, power); go.transform.rotation = Quaternion.Euler(startAngles + (eulerAngles * newValue)); yield return(null); } go.transform.rotation = Quaternion.Euler(startAngles + eulerAngles); }
public static IEnumerator moveObject(GameObject go, Vector3 direction, float duration, float distance, INTERPOLATION_TYPE type = INTERPOLATION_TYPE.SMOOTH, int power = 1) //direction normalized { Vector3 startPos = go.transform.localPosition; System.Func <float, float> interpolationFunc = getInterpolationFunc(type); //float delta = 0.0f; //float oldPos = 0.0f; float newPos = 0.0f; for (float i = 0; i < duration; i += Time.deltaTime) { //float pd = 0.25f + (i * 0.75f / duration); //TODO: make this line better mebbe float pd = i / duration; //TODO: ??? newPos = interpolationFunc(pd); newPos = Mathf.Pow(newPos, power); //delta = newPos - oldPos; //oldPos = newPos; go.transform.localPosition = startPos + (direction * newPos * distance); yield return(null); } go.transform.localPosition = startPos + (direction * distance); }