public static class MathUtilities {
//curve calculation for ease out effect
public static float Sinerp(float start, float end, float value) {
return Mathf.Lerp(start, end, Mathf.Sin(value * Mathf.PI * 0.5f));
}
//curve calculation for ease in effect
public static float Coserp(float start, float end, float value) {
return Mathf.Lerp(start, end, 1.0f - Mathf.Cos(value * Mathf.PI * 0.5f));
}
//curve calculation for easing at start + end
public static float CoSinLerp(float start, float end, float value) {
return Mathf.Lerp(start, end, value * value * (3.0f - 2.0f * value));
}
}
//jump sequence
IEnumerator doJump() {
float t = 0;
Vector3 startPos = GFX.transform.localPosition;
Vector3 endPos = new Vector3 (startPos.x, startPos.y + jumpHeight, startPos.z);
playerState.SetState (PLAYERSTATE.JUMPING);
isGrounded = false;
animator.Jump();
//adjust the jump animation speed so it fits with the height and time parameters
GFX.GetComponent<Animator>().SetFloat ("AnimationSpeed", 1f/jumpTime);
//going up
while (t < 1) {
GFX.transform.localPosition = Vector3.Lerp (startPos, endPos, MathUtilities.Sinerp (0, 1, t));
t += Time.deltaTime / (jumpTime / 2);
yield return null;
}
//going down
while (t > 0) {
GFX.transform.localPosition = Vector3.Lerp (startPos, endPos, MathUtilities.Sinerp (0, 1, t));
t -= Time.deltaTime / (jumpTime / 2);
yield return null;
}
GFX.transform.localPosition = startPos;
//show dust particles
animator.ShowDustEffect();
isGrounded = true;
}