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 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 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 ); }
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; } }
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); }