09-27-2020, 03:28 PM
(This post was last modified: 09-27-2020, 04:42 PM by DunchaLin3.)
Hi there. I have a problem with GetNearestPointTf. The point is that i have object with 2 child, between them i create a spline (lets name it A). After that, i need to check every spline crossing my A spline. I found the method GetNearestPointTf, but i cant find what i need. In addition, i can say that i have many of those objects. Can u please give me some hint, or maybe say what im doing wrong.
Code:
GameObject spline = new GameObject("CurveLine", typeof(CurvySpline), typeof(LineRenderer), typeof(CurvyLineRenderer));
spline.GetComponent<>(CurvySpline).Add(firstObject.transform.position, secondObject.transform.position);
float step = 2f;
Vector3 position = firstObject.transform.position;
while (position.z < secondObject.transform.position)
{
Vector3 inversePositionOnSpline = spline.transform.InverseTransformPoint(position);
float nearestTf = spline.GetComponent<CurvySpline>().GetNearestPointTF(inversePositionOnSpline);
Vector3 positionForSphere = spline.transform.TransformPoint(spline.GetComponent<CurvySpline>().Interpolate(nearestTf));
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = positionForSphere;
position.z += step;
}