using System; using UnityEngine; [AddComponentMenu("Modifiers/Warps/Hump")] public class MegaHumpWarp : MegaWarp { public float amount; public float cycles = 1f; public float phase; public bool animate; public float speed = 1f; public MegaAxis axis = MegaAxis.Z; private float amt; private Vector3 size = Vector3.zero; public override string WarpName() { return "Hump"; } public override string GetHelpURL() { return "?page_id=207"; } public override Vector3 Map(int i, Vector3 p) { p = tm.MultiplyPoint3x4(p); Vector3 a = p; float magnitude = p.magnitude; float t = Mathf.Exp((0f - totaldecay) * Mathf.Abs(magnitude)); switch (axis) { case MegaAxis.X: p.x += amt * Mathf.Sin(Mathf.Sqrt(p.x * p.x / size.x) + Mathf.Sqrt(p.y * p.y / size.y) * (float)Math.PI / 0.1f * ((float)Math.PI / 180f * cycles) + phase); break; case MegaAxis.Y: p.y += amt * Mathf.Sin(Mathf.Sqrt(p.y * p.y / size.y) + Mathf.Sqrt(p.x * p.x / size.x) * (float)Math.PI / 0.1f * ((float)Math.PI / 180f * cycles) + phase); break; case MegaAxis.Z: p.z += amt * Mathf.Sin(Mathf.Sqrt(p.x * p.x / size.x) + Mathf.Sqrt(p.y * p.y / size.y) * (float)Math.PI / 0.1f * ((float)Math.PI / 180f * cycles) + phase); break; } p = Vector3.Lerp(a, p, t); return invtm.MultiplyPoint3x4(p); } private void Update() { if (animate) { phase += Time.deltaTime * speed; } Prepare(Decay); } public override bool Prepare(float decay) { totaldecay = Decay + decay; if (totaldecay < 0f) { totaldecay = 0f; } tm = base.transform.worldToLocalMatrix; invtm = tm.inverse; size.x = Width; size.y = Height; size.z = Length; amt = amount / 100f; return true; } }