Created
August 7, 2017 17:34
-
-
Save j3ffgray/e4fbf7c16dee064069356ebb3c3a8220 to your computer and use it in GitHub Desktop.
Great Little Scale Tweak for GameObject in Unity - https://hastebin.com/fanosiwava.cs
This file contains 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