Skip to content

Instantly share code, notes, and snippets.

@embiem
Created July 5, 2017 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save embiem/7565e25fd612df6ea36b77f246ec0e5e to your computer and use it in GitHub Desktop.
Save embiem/7565e25fd612df6ea36b77f246ec0e5e to your computer and use it in GitHub Desktop.
Stretch object based on its speed and movement direction (original by @_pikopik https://twitter.com/_pikopik/status/882346033656844288) #Unity
using UnityEngine;
[ExecuteInEditMode]
public class DynamicScale : MonoBehaviour
{
Vector3 lastPosition;
void Start()
{
lastPosition = transform.position;
}
void LateUpdate()
{
Vector3 delta = transform.position - lastPosition;
transform.localRotation = Quaternion.LookRotation(delta + Vector3.forward * 0.001f);
float l = 1f + delta.magnitude;
float wh = Mathf.Sqrt(1f / l);
transform.localScale = new Vector3(wh, wh, l);
lastPosition = transform.position;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment