Created
July 5, 2017 11:39
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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