using UnityEngine; public class SimpleGainLocomotion : MonoBehaviour { public Transform Head; public float Gain = 1f; void Update() { Vector3 localPlayerPosition = this.transform.InverseTransformPoint(this.Head.position); Vector3 floorPosition = new Vector3(localPlayerPosition.x, 0f, localPlayerPosition.z); this.transform.localPosition = this.Gain * floorPosition; } #region Debug visualization void OnDrawGizmos() { if (!this.isActiveAndEnabled) return; Vector3 localPlayerPosition = this.transform.InverseTransformPoint(this.Head.position); Gizmos.color = Color.white; Gizmos.DrawLine(this.Head.position, localPlayerPosition); var playArea = this.GetComponent(); if (playArea != null) { Gizmos.color = Color.green; DrawWireframe(playArea.vertices, this.Gain + 1f); } } public void DrawWireframe(Vector3[] vertices, float scale) { if (vertices == null || vertices.Length == 0) return; var offset = transform.TransformVector(Vector3.up * 2f); for (int i = 0; i < 4; i++) { int next = (i + 1) % 4; var a = vertices[i] * scale; var b = a + offset; var c = vertices[next] * scale; var d = c + offset; Gizmos.DrawLine(a, b); Gizmos.DrawLine(a, c); Gizmos.DrawLine(b, d); } } #endregion }