Skip to content

Instantly share code, notes, and snippets.

@j3ffgray
Created August 7, 2017 17:34
Show Gist options
  • Save j3ffgray/e4fbf7c16dee064069356ebb3c3a8220 to your computer and use it in GitHub Desktop.
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
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