Skip to content

Instantly share code, notes, and snippets.

@keijiro
Created April 28, 2011 23:02
Show Gist options
  • Select an option

  • Save keijiro/947530 to your computer and use it in GitHub Desktop.

Select an option

Save keijiro/947530 to your computer and use it in GitHub Desktop.

Revisions

  1. keijiro revised this gist Apr 28, 2011. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion ExpEase.cs
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,8 @@ public static void Out2(ref Quaternion current, Quaternion target, float coeff)
    public static void OutLocalTransform(Transform current, Vector3 targetPosition,
    Quaternion targetRotation, float coeff) {
    coeff = Mathf.Exp(coeff * Time.deltaTime);
    current.localPosition = Vector3.Lerp(targetPosition, current.localPosition, coeff);
    current.localPosition = Vector3.Lerp(targetPosition,
    current.localPosition, coeff);
    if (current.localRotation == targetRotation) {
    current.localRotation = targetRotation;
    } else {
  2. keijiro revised this gist Apr 28, 2011. 1 changed file with 48 additions and 28 deletions.
    76 changes: 48 additions & 28 deletions ExpEase.cs
    Original file line number Diff line number Diff line change
    @@ -1,46 +1,66 @@
    // Example:
    //
    // currentPos = ExpEase.Out(currentPos, targetPos, -4.0);
    //
    // or
    //
    // ExpEase.Out2(currentPos, targetPos, -4.0); // This modifies currentPos.
    //

    using UnityEngine;

    public static class ExpEase {
    public static float Out(float current, float target, float coeff) {
    return target - (target - current) * Mathf.Exp(coeff * Time.deltaTime);
    return target - (target - current) * Mathf.Exp(coeff * Time.deltaTime);
    }

    public static float OutAngle(float current, float target, float coeff) {
    return target - Mathf.DeltaAngle(current, target) * Mathf.Exp(coeff * Time.deltaTime);
    return target -
    Mathf.DeltaAngle(current, target) * Mathf.Exp(coeff * Time.deltaTime);
    }

    public static Vector3 Out(Vector3 current, Vector3 target, float coeff) {
    return Vector3.Lerp(target, current, Mathf.Exp(coeff * Time.deltaTime));
    return Vector3.Lerp(target, current, Mathf.Exp(coeff * Time.deltaTime));
    }

    public static Quaternion Out(Quaternion current, Quaternion target, float coeff) {
    if (current == target) {
    return target;
    } else {
    return Quaternion.Lerp(target, current, Mathf.Exp(coeff * Time.deltaTime));
    }
    if (current == target) {
    return target;
    } else {
    return Quaternion.Lerp(target, current, Mathf.Exp(coeff * Time.deltaTime));
    }
    }

    public static void Out2(ref float current, float target, float coeff) {
    current = target - (target - current) * Mathf.Exp(coeff * Time.deltaTime);
    current = target - (target - current) * Mathf.Exp(coeff * Time.deltaTime);
    }

    public static void OutAngle2(ref float current, float target, float coeff) {
    current = target - Mathf.DeltaAngle(current, target) * Mathf.Exp(coeff * Time.deltaTime);
    current = target -
    Mathf.DeltaAngle(current, target) * Mathf.Exp(coeff * Time.deltaTime);
    }

    public static void Out2(ref Vector3 current, Vector3 target, float coeff) {
    current = Vector3.Lerp(target, current, Mathf.Exp(coeff * Time.deltaTime));
    current = Vector3.Lerp(target, current, Mathf.Exp(coeff * Time.deltaTime));
    }

    public static void Out2(ref Quaternion current, Quaternion target, float coeff) {
    if (current == target) {
    current = target;
    } else {
    current = Quaternion.Lerp(target, current, Mathf.Exp(coeff * Time.deltaTime));
    }
    }

    public static void OutLocalTransform(Transform current, Vector3 targetPosition, Quaternion targetRotation, float coeff) {
    coeff = Mathf.Exp(coeff * Time.deltaTime);
    current.localPosition = Vector3.Lerp(targetPosition, current.localPosition, coeff);
    if (current.localRotation == targetRotation) {
    current.localRotation = targetRotation;
    } else {
    current.localRotation = Quaternion.Lerp(targetRotation, current.localRotation, coeff);
    }
    }
    }
    if (current == target) {
    current = target;
    } else {
    current = Quaternion.Lerp(target, current, Mathf.Exp(coeff * Time.deltaTime));
    }
    }

    public static void OutLocalTransform(Transform current, Vector3 targetPosition,
    Quaternion targetRotation, float coeff) {
    coeff = Mathf.Exp(coeff * Time.deltaTime);
    current.localPosition = Vector3.Lerp(targetPosition, current.localPosition, coeff);
    if (current.localRotation == targetRotation) {
    current.localRotation = targetRotation;
    } else {
    current.localRotation = Quaternion.Lerp(targetRotation,
    current.localRotation, coeff);
    }
    }
    }
  3. keijiro created this gist Apr 28, 2011.
    46 changes: 46 additions & 0 deletions ExpEase.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    using UnityEngine;
    public static class ExpEase {
    public static float Out(float current, float target, float coeff) {
    return target - (target - current) * Mathf.Exp(coeff * Time.deltaTime);
    }
    public static float OutAngle(float current, float target, float coeff) {
    return target - Mathf.DeltaAngle(current, target) * Mathf.Exp(coeff * Time.deltaTime);
    }
    public static Vector3 Out(Vector3 current, Vector3 target, float coeff) {
    return Vector3.Lerp(target, current, Mathf.Exp(coeff * Time.deltaTime));
    }
    public static Quaternion Out(Quaternion current, Quaternion target, float coeff) {
    if (current == target) {
    return target;
    } else {
    return Quaternion.Lerp(target, current, Mathf.Exp(coeff * Time.deltaTime));
    }
    }

    public static void Out2(ref float current, float target, float coeff) {
    current = target - (target - current) * Mathf.Exp(coeff * Time.deltaTime);
    }
    public static void OutAngle2(ref float current, float target, float coeff) {
    current = target - Mathf.DeltaAngle(current, target) * Mathf.Exp(coeff * Time.deltaTime);
    }
    public static void Out2(ref Vector3 current, Vector3 target, float coeff) {
    current = Vector3.Lerp(target, current, Mathf.Exp(coeff * Time.deltaTime));
    }
    public static void Out2(ref Quaternion current, Quaternion target, float coeff) {
    if (current == target) {
    current = target;
    } else {
    current = Quaternion.Lerp(target, current, Mathf.Exp(coeff * Time.deltaTime));
    }
    }

    public static void OutLocalTransform(Transform current, Vector3 targetPosition, Quaternion targetRotation, float coeff) {
    coeff = Mathf.Exp(coeff * Time.deltaTime);
    current.localPosition = Vector3.Lerp(targetPosition, current.localPosition, coeff);
    if (current.localRotation == targetRotation) {
    current.localRotation = targetRotation;
    } else {
    current.localRotation = Quaternion.Lerp(targetRotation, current.localRotation, coeff);
    }
    }
    }