Skip to content

Instantly share code, notes, and snippets.

@Starpelly
Last active November 20, 2023 13:30
Show Gist options
  • Save Starpelly/b3588724c924310bb362c8571426a11c to your computer and use it in GitHub Desktop.
Save Starpelly/b3588724c924310bb362c8571426a11c to your computer and use it in GitHub Desktop.
Simple Squash Stretch, can be used for pretty much anything. (Celeste-like effect)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SimpleSquashStretch : MonoBehaviour {
public Vector3 wallSquash = new Vector3(1.66f, 0.7f, 0.1f);
public Sprite m_SpriteRenderer;
void Start()
{
//Example
StartCoroutine(JumpSqueeze(wallSquash.x, wallSquash.y, wallSquash.z, true));
}
IEnumerator JumpSqueeze(float xSqueeze, float ySqueeze, float seconds, bool isInstant)
{
Vector3 originalSize = Vector3.one;
Vector3 newSize = new Vector3(xSqueeze, ySqueeze, originalSize.z);
float t = 0f;
if (isInstant == false)
{
while (t <= 1.0)
{
t += Time.deltaTime / seconds;
m_SpriteRenderer.transform.localScale = Vector3.Lerp(originalSize, newSize, t);
yield return null;
}
t = 0f;
}
while (t <= 1.0)
{
t += Time.deltaTime / seconds;
m_SpriteRenderer.transform.localScale = Vector3.Lerp(newSize, originalSize, t);
yield return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment