5 using System.Collections.Generic;
12 public Vector3 BulgeCenter
16 return transform.TransformPoint(bulgeCenter);
20 bulgeCenter = transform.InverseTransformPoint(value);
25 private Vector3 bulgeCenter = Vector3.zero;
27 private AnimationCurve bulgeFalloff =
new AnimationCurve();
29 private float bulgeRadius = 1f;
31 private float scaleDistort = 2f;
33 private float bulgeStrength = 1f;
37 float distanceToCenter = Vector3.Distance(point, BulgeCenter);
38 if (distanceToCenter < bulgeRadius)
40 float distortion = (1f - (bulgeFalloff.Evaluate(distanceToCenter / bulgeRadius))) * bulgeStrength;
41 Vector3 direction = (point - BulgeCenter).normalized;
42 point = point + (direction * distortion * bulgeStrength);
49 float distanceToCenter = Vector3.Distance(point, BulgeCenter);
50 if (distanceToCenter < bulgeRadius)
52 float distortion = (1f - (bulgeFalloff.Evaluate(distanceToCenter / bulgeRadius))) * bulgeStrength;
53 return Vector3.one + (Vector3.one * distortion * scaleDistort);
58 private void OnDrawGizmos()
60 Vector3 bulgePoint = transform.TransformPoint(bulgeCenter);
61 Color gColor = Color.red;
63 Gizmos.color = gColor;
64 Gizmos.DrawWireSphere(bulgePoint, bulgeRadius);
66 for (
int i = 0; i < steps; i++)
68 float normalizedStep = (1f / steps) * i;
69 gColor.a = (1f - bulgeFalloff.Evaluate(normalizedStep)) * 0.5f;
70 Gizmos.color = gColor;
71 Gizmos.DrawSphere(bulgePoint, bulgeRadius * bulgeFalloff.Evaluate(normalizedStep));