protected override void UpdateValue(float time) { Vector2 nextPosition; if (time <= 0.5f) { nextPosition = new Vector2( Mathf.Lerp(_startPosition.x, _middlePosition.x, time * 2f), EaseFunctions.OutCirc(_startPosition.y, _middlePosition.y, time * 2f)); } else { nextPosition = new Vector2( Mathf.Lerp(_middlePosition.x, _targetPosition.x, time * 2f - 1f), EaseFunctions.InCirc(_middlePosition.y, _targetPosition.y, time * 2f - 1f)); } if (_isLocal) { transform.localPosition = nextPosition; } else { transform.position = nextPosition; } }
public void UpdateVertexEffect(TMP_CharacterInfo charInfo, ref EffectData data) { var t = Mathf.Clamp01(progress - data.index); t = EaseFunctions.Ease(easeType, t); var delta = endScale - startScale; data.localScale = startScale + delta * t; //Vector3.Lerp(startScale, endScale, t ); }
public bool Update(float dt) { this.delay -= dt; if (this.delay <= 0f) { this.timer += (dt / this.duration) * this.direction; try { if (this.onUpdate != null) { this.onUpdate.Invoke(this.obj, EaseFunctions.GetEase(this.easeFunction).Invoke(this.timer, this.@from, this.to, 1f)); } if (this.timer >= 1f) { if (this.reflect == true) { this.direction = -1f; return(false); } --this.loops; if (this.loops == 0) { return(true); } return(false); } else if (this.timer <= 0f) { --this.loops; if (this.loops == 0) { return(true); } if (this.reflect == true) { this.direction = 1f; return(false); } return(false); } } catch (System.Exception ex) { Debug.LogException(ex); } if (this.timer >= 1f) { return(true); } } return(false); }
public void UpdateVertexEffect(TMP_CharacterInfo charInfo, ref EffectData data) { var t = Mathf.Clamp01(progress - data.index); t = EaseFunctions.Ease(easeType, t); var delta = endOffset - startOffset; data.localPosition = startOffset + delta * t; }
public override void UpdateVertexEffect(TMP_CharacterInfo charInfo, ref EffectData data) { var t = Mathf.Clamp01(progress - data.Index); t = EaseFunctions.Ease(easeType, t); var delta = endScale - startScale; data.LocalScale = startScale + delta * t; }
public void TestBounceEaseOutStart() { double time = 0, startingValue = 20, valueOffset = 100, duration = 50; Assert.AreEqual( startingValue, EaseFunctions.BounceEaseOut(time, startingValue, valueOffset, duration)); }
public void TestBounceEaseOutEnd() { double time = 50, positionPixelsStart = 20, poistionPixelsOffset = 100, duration = 50, positionPixelsEnd; positionPixelsEnd = positionPixelsStart + poistionPixelsOffset; Assert.AreEqual( positionPixelsEnd, EaseFunctions.BounceEaseOut(time, positionPixelsStart, poistionPixelsOffset, duration)); }
private void Update() { if (state == GateStates.Closed || state == GateStates.Open) { return; } elapsed += Time.deltaTime; if (elapsed >= currentDuration) { if (state != GateStates.Holding) { transform.position = new Vector3(targetPosition.x, targetPosition.y, ZValue); } elapsed -= currentDuration; switch (state) { case GateStates.Stutter: state = GateStates.Holding; currentDuration = holdTime; break; case GateStates.Holding: state = GateStates.Opening; basePosition = targetPosition; targetPosition = originalPosition + new Vector2(0, height); currentDuration = openDuration; break; case GateStates.Opening: state = GateStates.Open; return; } } if (state != GateStates.Holding) { float amount = elapsed / currentDuration; EaseTypes easeType = state == GateStates.Stutter ? EaseTypes.CubicOut : EaseTypes.CubicIn; Vector2 p = Vector2.Lerp(basePosition, targetPosition, EaseFunctions.Ease(amount, easeType)); // Adding a small Z value causes gates to render behind the tilemap as they open. transform.position = new Vector3(p.x, p.y, ZValue); } }
void FixedUpdate() { HandleFixedUpdate(); TweenMoveDir = EaseFunctions.Ease(EaseFunctions.Type.Linear, TweenValue, TweenMoveDir, MoveDir - TweenMoveDir, 1.0f); RaycastHit2D[] results = new RaycastHit2D[10]; Vector3 newPos = new Vector3(transform.position.x, transform.position.y); RaycastHit2D result = Physics2D.BoxCast(new Vector2(newPos.x + boxCollider.size.x / 4f * (TweenMoveDir.x > 0 ? 1 : -1), newPos.y + boxCollider.offset.y), new Vector2(boxCollider.size.x / 2f, boxCollider.size.y * .5f), 0, Vector2.right, TweenMoveDir.x * speed * MOVEMENT_MULTIPLIER, StopMovementMask); if (result.collider != null) { if (TweenMoveDir.x > 0) { newPos.x = result.collider.bounds.center.x - result.collider.bounds.extents.x - boxCollider.size.x / 2f; } else if (TweenMoveDir.x < 0) { newPos.x = result.collider.bounds.center.x + result.collider.bounds.extents.x + boxCollider.size.x / 2f; } } else { newPos.x += TweenMoveDir.x * speed * MOVEMENT_MULTIPLIER; } result = Physics2D.BoxCast(new Vector2(newPos.x, newPos.y + boxCollider.offset.y + boxCollider.size.y / 4f * (TweenMoveDir.y > 0 ? 1 : -1)), new Vector2(boxCollider.size.x * .5f, boxCollider.size.y / 2f), 0, Vector2.up, TweenMoveDir.y * speed * MOVEMENT_MULTIPLIER, StopMovementMask); if (result.collider != null) { if (TweenMoveDir.y > 0) { newPos.y = result.collider.bounds.center.y - result.collider.bounds.extents.y - boxCollider.offset.y - boxCollider.size.y / 2f; } else if (TweenMoveDir.y < 0) { newPos.y = result.collider.bounds.center.y + result.collider.bounds.extents.y - boxCollider.offset.y + boxCollider.size.y / 2f; } } else { newPos.y += TweenMoveDir.y * speed * MOVEMENT_MULTIPLIER; } transform.position = newPos; // Debug.Log(boxCollider.Cast(TweenMoveDir, results));// (f, results)); }
public void UpdateColorEffect(TMP_CharacterInfo charInfo, ref EffectData data) { var left = EaseFunctions.Ease(easeType, 1 - Mathf.Clamp01(data.index - (progress - 0.5f))); data.color0.a = (byte)Mathf.Round(255 * left); data.color1.a = (byte)Mathf.Round(255 * left); if (smooth) { var right = EaseFunctions.Ease(easeType, 1 - Mathf.Clamp01(data.index - (progress - 1f))); data.color2.a = (byte)Mathf.Round(255 * right); data.color3.a = (byte)Mathf.Round(255 * right); } else { data.color2.a = (byte)Mathf.Round(255 * left); data.color3.a = (byte)Mathf.Round(255 * left); } }
private void Launch() { Vector2 v = body.velocity; float angle = Mathf.Abs(Mathf.Atan2(launchVector.y, launchVector.x)); float halfReversalRange = forcedReversalRange / 2; if (angle > Mathf.PI / 2) { angle = Mathf.PI - angle; } float t = EaseFunctions.Ease(elapsed / maximumChargeTime, EaseTypes.QuadraticOut); float force = (maximumForce - minimumForce) * t + minimumForce; // This correction mean it's easier to quickly reverse X direction through a quick, weak launch. if (Math.Sign(v.x * launchVector.x) <= 0 && angle <= halfReversalRange) { v.x = 0; // This spin correction is comparable to the special case in FixedUpdate. body.angularVelocity = -launchVector.x * force * launchAngularVelocityFactor; } // If a launch is aimed upwards while falling, the falling speed is negated. This makes it easier to stay // airborne. if (launchVector.y > 0 && v.y < 0) { v.y = 0; } body.velocity = v; body.AddForce(launchVector * force); TotalJumps++; justLaunched = true; charging = false; chargeBar.Charge = 0; spring.targetValue = 1; launchSound.pitch = t * (maximumPitch - minimumPitch) + minimumPitch; launchSound.Play(); }
public void UpdateColorEffect(TMP_CharacterInfo charInfo, ref EffectData data) { var left = EaseFunctions.Ease(easeType, 1 - Mathf.Clamp01(data.Index - (progress - 0.5f))); var leftAlpha = (byte)Mathf.Round(255 * left); data.SetAlpha(0, leftAlpha); data.SetAlpha(1, leftAlpha); if (smooth) { var right = EaseFunctions.Ease(easeType, 1 - Mathf.Clamp01(data.Index - (progress - 1f))); var rightAlpha = (byte)Mathf.Round(255 * right); data.SetAlpha(2, rightAlpha); data.SetAlpha(3, rightAlpha); } else { data.SetAlpha(2, leftAlpha); data.SetAlpha(3, leftAlpha); } }
private void FixedUpdate() { // Moving platforms start stationary, then, when activated, move towards their target location over a preset // duration, hold the target position, then cycle back. if (!active) { return; } elapsed += Time.deltaTime; if (moving) { Vector2 start = movingAway ? spawnPosition : targetPosition; Vector2 end = movingAway ? targetPosition : spawnPosition; if (elapsed >= movementDuration) { body.position = end; moving = false; active = movingAway; movingAway = !movingAway; elapsed = 0; } else { body.position = Vector2.Lerp(start, end, EaseFunctions.Ease(elapsed / movementDuration, EaseTypes.QuadraticInOut)); } } else if (elapsed > stallDuration) { elapsed = 0; moving = true; } }
public TweenBase SetEase(Ease ease) { EaseFunc = EaseFunctions.Get(ease); return(this); }
private static float Interpolate(EaseFunctions easeFunction, float t) { switch (easeFunction) { case EaseFunctions.EASE_IN_SINE: return(1 - Mathf.Cos((t * Mathf.PI) / 2)); case EaseFunctions.EASE_OUT_SINE: return(Mathf.Sin((t * Mathf.PI) / 2)); case EaseFunctions.EASE_IN_OUT_SINE: return(-(Mathf.Cos(Mathf.PI * t) - 1) / 2); case EaseFunctions.EASE_IN_QUAD: return(t * t); case EaseFunctions.EASE_OUT_QUAD: return(1 - (1 - t) * (1 - t)); case EaseFunctions.EASE_IN_OUT_QUAD: return(t < 0.5 ? 2 * t * t : 1 - Mathf.Pow(-2 * t + 2, 2) / 2); case EaseFunctions.EASE_IN_CUBIC: return(t * t * t); case EaseFunctions.EASE_OUT_CUBIC: return(1 - Mathf.Pow(1 - t, 3)); case EaseFunctions.EASE_IN_OUT_CUBIC: return(t < 0.5 ? 4 * t * t * t : 1 - Mathf.Pow(-2 * t + 2, 3) / 2); case EaseFunctions.EASE_IN_QUART: return(t * t * t * t); case EaseFunctions.EASE_OUT_QUART: return(1 - Mathf.Pow(1 - t, 4)); case EaseFunctions.EASE_IN_OUT_QUART: return(t < 0.5 ? 8 * t * t * t * t : 1 - Mathf.Pow(-2 * t + 2, 4) / 2); case EaseFunctions.EASE_IN_QUINT: return(t * t * t * t * t); case EaseFunctions.EASE_OUT_QUINT: return(1 - Mathf.Pow(1 - t, 5)); case EaseFunctions.EASE_IN_OUT_QUINT: return(t < 0.5 ? 16 * t * t * t * t * t : 1 - Mathf.Pow(-2 * t + 2, 5) / 2); case EaseFunctions.EASE_IN_EXPO: return(t <= 0.001f ? 0 : Mathf.Pow(2, 10 * t - 10)); case EaseFunctions.EASE_OUT_EXPO: return(t >= 0.999f ? 1f : 1f - Mathf.Pow(2, -10 * t)); case EaseFunctions.EASE_IN_OUT_EXPO: if (t <= 0.001f) { return(0f); } if (t >= 0.999f) { return(1f); } if (t < 0.5f) { return(Mathf.Pow(2f, 20f * t - 10f) / 2f); } return((2f - Mathf.Pow(2f, -20f * t + 10f)) / 2f); case EaseFunctions.EASE_IN_CIRC: return(1 - Mathf.Sqrt(1 - Mathf.Pow(t, 2))); case EaseFunctions.EASE_OUT_CIRC: return(Mathf.Sqrt(1 - Mathf.Pow(t - 1, 2))); case EaseFunctions.EASE_IN_OUT_CIRC: return(t < 0.5f ? (1f - Mathf.Sqrt(1f - Mathf.Pow(2f * t, 2f))) / 2f : (Mathf.Sqrt(1f - Mathf.Pow(-2f * t + 2f, 2f)) + 1f) / 2f); case EaseFunctions.EASE_IN_BACK: var a1 = 1.70158f; var a3 = a1 + 1f; return(a3 * t * t * t - a1 * t * t); case EaseFunctions.EASE_OUT_BACK: var b1 = 1.70158f; var b3 = b1 + 1f; return(1f + b3 * Mathf.Pow(t - 1f, 3f) + b1 * Mathf.Pow(t - 1f, 2f)); case EaseFunctions.EASE_IN_OUT_BACK: var c1 = 1.70158f; var c2 = c1 * 1.525f; return(t < 0.5 ? (Mathf.Pow(2 * t, 2) * ((c2 + 1) * 2 * t - c2)) / 2 : (Mathf.Pow(2 * t - 2, 2) * ((c2 + 1) * (t * 2 - 2) + c2) + 2) / 2); case EaseFunctions.EASE_IN_ELASTIC: var d4 = (float)(2f * Math.PI) / 3f; return(t <= 0.001f ? 0f : t >= 0.999f ? 1f : -Mathf.Pow(2f, 10f * t - 10f) * Mathf.Sin((t * 10f - 10.75f) * d4)); case EaseFunctions.EASE_OUT_ELASTIC: var e4 = (float)(2f * Math.PI) / 3f; return(t <= 0.001f ? 0f : t >= 0.999f ? 1f : Mathf.Pow(2f, -10f * t) * Mathf.Sin((t * 10f - 0.75f) * e4) + 1f); case EaseFunctions.EASE_IN_OUT_ELASTIC: var f5 = (float)(2f * Math.PI) / 4.5f; return(t <= 0.001f ? 0f : t >= 0.999f ? 1f : t < 0.5f ? -(Mathf.Pow(2f, 20f * t - 10f) * Mathf.Sin((20f * t - 11.125f) * f5)) / 2f : (Mathf.Pow(2f, -20f * t + 10f) * Mathf.Sin((20f * t - 11.125f) * f5)) / 2f + 1f); case EaseFunctions.EASE_IN_BOUNCE: return(1f - Interpolate(EaseFunctions.EASE_OUT_BOUNCE, 1f - t)); case EaseFunctions.EASE_OUT_BOUNCE: var n1 = 7.5625f; var d1 = 2.75f; if (t < 1f / d1) { return(n1 * t * t); } else if (t < 2f / d1) { return(n1 * (t -= 1.5f / d1) * t + 0.75f); } else if (t < 2.5f / d1) { return(n1 * (t -= 2.25f / d1) * t + 0.9375f); } else { return(n1 * (t -= 2.625f / d1) * t + 0.984375f); } case EaseFunctions.EASE_IN_OUT_BOUNCE: return(t < 0.5f ? (1 - Interpolate(EaseFunctions.EASE_OUT_BOUNCE, 1f - 2f * t)) / 2f : (1 + Interpolate(EaseFunctions.EASE_OUT_BOUNCE, 2f * t - 1f)) / 2f); default: throw new ArgumentOutOfRangeException(nameof(easeFunction), easeFunction, null); } }
public static float Ease(float a, float b, EaseFunctions easeFunction, float t) { var tweened = Interpolate(easeFunction, Mathf.Clamp01(t)); return(Mathf.LerpUnclamped(a, b, tweened)); }
public static Quaternion Ease(Quaternion a, Quaternion b, EaseFunctions easeFunction, float t) { var tweened = Interpolate(easeFunction, Mathf.Clamp01(t)); return(Quaternion.LerpUnclamped(a, b, tweened)); }
public static Vector3 Ease(Vector3 a, Vector3 b, EaseFunctions easeFunction, float t) { var tweened = Interpolate(easeFunction, Mathf.Clamp01(t)); return(Vector3.LerpUnclamped(a, b, tweened)); }
public void UpdateEase(int easeInt) { EaseFunc = EaseFunctions.Get((Ease)easeInt); }
static public float CalculateEaseInverse(EaseFunctions function, EaseDirections direction, float x) { switch (function) { case EaseFunctions.Linear: return(Linear(x)); case EaseFunctions.Quadratic: switch (direction) { case EaseDirections.In: return(QuadraticInInverse(x)); case EaseDirections.Out: return(QuadraticOutInverse(x)); case EaseDirections.InOut: return(QuadraticInOutInverse(x)); default: Debug.LogError("Ease Function Inverse Enum Out of Bounds Error"); return(0); } case EaseFunctions.Cubic: switch (direction) { case EaseDirections.In: return(CubicInInverse(x)); case EaseDirections.Out: return(CubicOutInverse(x)); case EaseDirections.InOut: return(CubicInOutInverse(x)); default: Debug.LogError("Ease Function Inverse Enum Out of Bounds Error"); return(0); } case EaseFunctions.Quartic: switch (direction) { case EaseDirections.In: return(QuarticInInverse(x)); case EaseDirections.Out: return(QuarticOutInverse(x)); case EaseDirections.InOut: return(QuarticInOutInverse(x)); default: Debug.LogError("Ease Function Inverse Enum Out of Bounds Error"); return(0); } case EaseFunctions.Quintic: switch (direction) { case EaseDirections.In: return(QuinticInInverse(x)); case EaseDirections.Out: return(QuinticOutInverse(x)); case EaseDirections.InOut: return(QuinticInOutInverse(x)); default: Debug.LogError("Ease Function Inverse Enum Out of Bounds Error"); return(0); } case EaseFunctions.Sine: switch (direction) { case EaseDirections.In: return(SineInInverse(x)); case EaseDirections.Out: return(SineOutInverse(x)); case EaseDirections.InOut: return(SineInOutInverse(x)); default: Debug.LogError("Ease Function Inverse Enum Out of Bounds Error"); return(0); } case EaseFunctions.Circular: switch (direction) { case EaseDirections.In: return(CircularInInverse(x)); case EaseDirections.Out: return(CircularOutInverse(x)); case EaseDirections.InOut: return(CircularInOutInverse(x)); default: Debug.LogError("Ease Function Inverse Enum Out of Bounds Error"); return(0); } case EaseFunctions.Exponential: switch (direction) { case EaseDirections.In: return(ExponentialInInverse(x)); case EaseDirections.Out: return(ExponentialOutInverse(x)); case EaseDirections.InOut: return(ExponentialInOutInverse(x)); default: Debug.LogError("Ease Function Inverse Enum Out of Bounds Error"); return(0); } ; case EaseFunctions.Elastic: switch (direction) { case EaseDirections.In: return(ElasticInInverse(x)); case EaseDirections.Out: return(ElasticOutInverse(x)); case EaseDirections.InOut: return(ElasticInOutInverse(x)); default: Debug.LogError("Ease Function Inverse Enum Out of Bounds Error"); return(0); } case EaseFunctions.Back: switch (direction) { case EaseDirections.In: return(BackInInverse(x)); case EaseDirections.Out: return(BackOutInverse(x)); case EaseDirections.InOut: return(BackInOutInverse(x)); default: Debug.LogError("Ease Function Inverse Enum Out of Bounds Error"); return(0); } case EaseFunctions.Bounce: switch (direction) { case EaseDirections.In: return(BounceInInverse(x)); case EaseDirections.Out: return(BounceOutInverse(x)); case EaseDirections.InOut: return(BounceInOutInverse(x)); default: Debug.LogError("Ease Function Inverse Enum Out of Bounds Error"); return(0); } default: Debug.LogError("Ease Function Inverse Enum Out of Bounds Error"); return(0); } }
private void Update() { // Quitting code would ordinarily be managed in a menu, but for this project, it's easier to put it here (since // there's one persistent copy of the player and the player is present in every scene). if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } if (inputLocked) { return; } justLaunched = false; Vector2 mousePosition = Input.mousePosition; Vector2 playerPosition = transform.position; // The mouse overrides joystick aim if the mouse was moved this frame. if (mousePosition != previousMouseScreenPosition) { Vector2 worldPosition = Camera.main.ScreenToWorldPoint(mousePosition); previousMouseScreenPosition = mousePosition; launchVector = (worldPosition - playerPosition).normalized; } else { Vector2 joystickVector = new Vector2(Input.GetAxis("Joystick X"), -Input.GetAxis("Joystick Y")); if (joystickVector != Vector2.zero) { launchVector = joystickVector.normalized; } } if (charging) { elapsed += Time.deltaTime; elapsed = Mathf.Min(elapsed, maximumChargeTime); float t = EaseFunctions.Ease(elapsed / maximumChargeTime, EaseTypes.QuadraticOut); chargeBar.Charge = t; spring.targetValue = 1 - maximumSquishiness * t; if (Input.GetButtonUp("Launch") && launchVector != Vector2.zero) { Launch(); } } else if (Input.GetButtonDown("Launch")) { elapsed = 0; charging = true; } float launchRotation = Mathf.Atan2(launchVector.y, launchVector.x) * Mathf.Rad2Deg; Vector2 barPosition = playerPosition + launchVector * barOffset; Transform arrowTransform = chargeBar.transform; arrowTransform.position = new Vector3(barPosition.x, barPosition.y, BarZ); arrowTransform.rotation = Quaternion.Euler(0, 0, launchRotation); spring.Update(); transform.localScale = new Vector3(spring.value, spring.value, 1); }