46 lines
829 B
C#
46 lines
829 B
C#
using UnityEngine;
|
|
|
|
public class MegaShapeRBodyPath : MonoBehaviour
|
|
{
|
|
public MegaShape target;
|
|
|
|
public int curve;
|
|
|
|
public float force = 1f;
|
|
|
|
public float alpha;
|
|
|
|
public bool usealpha;
|
|
|
|
private Rigidbody rb;
|
|
|
|
private void Update()
|
|
{
|
|
if ((bool)target)
|
|
{
|
|
target.selcurve = curve;
|
|
Vector3 position = base.transform.position;
|
|
Vector3 vector;
|
|
if (usealpha)
|
|
{
|
|
vector = target.transform.TransformPoint(target.InterpCurve3D(curve, alpha, true));
|
|
}
|
|
else
|
|
{
|
|
Vector3 tangent = Vector3.zero;
|
|
int kn = 0;
|
|
vector = target.FindNearestPointWorld(position, 5, ref kn, ref tangent, ref alpha);
|
|
}
|
|
if (rb == null)
|
|
{
|
|
rb = GetComponent<Rigidbody>();
|
|
}
|
|
if ((bool)rb)
|
|
{
|
|
Vector3 vector2 = vector - position;
|
|
rb.AddForce(vector2 * (force / vector2.magnitude));
|
|
}
|
|
}
|
|
}
|
|
}
|