Skip to main content
added 183 characters in body
Source Link

So earlier I was just normalizing the tangents with length 1 which was creating problems since as I mentioned in the question that tangent length affects the curvature of the path so I modified that by reducing the length of the tangents, proportionally to the distance between points. distanceBetweenPoints

The value 0.8 is something that worked(I liked the onelook of it) for me so basically, my thought process behind that correctsis to keep 80% of the distance of 2 points instead of keeping 100% thus retaining the tangent lengthbetween points.

Vector3 tangentLS = default;
        for (int i = 0; i < ropeSaveData.ropeCurvePoints.Count; i++)
        {
            // Calculate control point positions and tangent vector:
            Vector3 currentPointPosition =
                generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i]);
            if (i == 0)
            {
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                float distanceBetweenPoints = Vector3.Distance(nextPointPosition, currentPointPosition);
                distanceBetweenPoints = distanceBetweenPoints * 0.8f;
                tangentLS = (nextPointPosition - currentPointPosition).normalized * distanceBetweenPoints;0.8;
            }
            else if (i < ropeSaveData.ropeCurvePoints.Count - 1)
            {
                Vector3 previousPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i - 1]);
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                float distanceBetweenPoints = Vector3.Distance(nextPointPosition, currentPointPosition);
                distanceBetweenPoints = distanceBetweenPoints * 0.8f;
                tangentLS = (nextPointPosition - previousPointPosition).normalized * distanceBetweenPoints;0.8;
            }

            // Build the rope path:
            blueprint.path.AddControlPoint(currentPointPosition, -tangentLS, tangentLS, Vector3.up,
                0.1f, 0.1f, 1, filter, Color.white, "start_" + i);
        }

So earlier I was just normalizing the tangents with length 1 which was creating problems since as I mentioned in the question that tangent length affects the curvature of the path so I modified that by reducing the length of the tangents, proportionally to the distance between points. distanceBetweenPoints is the one that corrects the tangent length.

Vector3 tangentLS = default;
        for (int i = 0; i < ropeSaveData.ropeCurvePoints.Count; i++)
        {
            // Calculate control point positions and tangent vector:
            Vector3 currentPointPosition =
                generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i]);
            if (i == 0)
            {
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                float distanceBetweenPoints = Vector3.Distance(nextPointPosition, currentPointPosition);
                distanceBetweenPoints = distanceBetweenPoints * 0.8f;
                tangentLS = (nextPointPosition - currentPointPosition).normalized * distanceBetweenPoints;
            }
            else if (i < ropeSaveData.ropeCurvePoints.Count - 1)
            {
                Vector3 previousPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i - 1]);
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                float distanceBetweenPoints = Vector3.Distance(nextPointPosition, currentPointPosition);
                distanceBetweenPoints = distanceBetweenPoints * 0.8f;
                tangentLS = (nextPointPosition - previousPointPosition).normalized * distanceBetweenPoints;
            }

            // Build the rope path:
            blueprint.path.AddControlPoint(currentPointPosition, -tangentLS, tangentLS, Vector3.up,
                0.1f, 0.1f, 1, filter, Color.white, "start_" + i);
        }

So earlier I was just normalizing the tangents with length 1 which was creating problems since as I mentioned in the question that tangent length affects the curvature of the path so I modified that by reducing the length of the tangents, proportionally to the distance between points.

The value 0.8 is something that worked(I liked the look of it) for me so basically, my thought process behind that is to keep 80% of the distance of 2 points instead of keeping 100% thus retaining the tangent between points.

Vector3 tangentLS = default;
        for (int i = 0; i < ropeSaveData.ropeCurvePoints.Count; i++)
        {
            // Calculate control point positions and tangent vector:
            Vector3 currentPointPosition =
                generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i]);
            if (i == 0)
            {
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                
                tangentLS = (nextPointPosition - currentPointPosition) * 0.8;
            }
            else if (i < ropeSaveData.ropeCurvePoints.Count - 1)
            {
                Vector3 previousPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i - 1]);
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
              
                tangentLS = (nextPointPosition - previousPointPosition) * 0.8;
            }

            // Build the rope path:
            blueprint.path.AddControlPoint(currentPointPosition, -tangentLS, tangentLS, Vector3.up,
                0.1f, 0.1f, 1, filter, Color.white, "start_" + i);
        }
added 822 characters in body
Source Link

Thank you @DMGregory for pointing me out in the right direction.

So earlier I was just normalizing the tangents with helplength 1 which was creating problems since as I mentioned in the question that tangent length affects the curvature of @DMGregory.the path so I mademodified that by reducing the length of the tangents, proportionally to the distance between points. distanceBetweenPoints is the one that corrects the tangent length.

Now it work withis working perfectly fine. Here's the followingupdated code.:

Vector3 tangentLS = default;
        for (int i = 0; i < ropeSaveData.ropeCurvePoints.Count; i++)
        {
            // Calculate control point positions and tangent vector:
            Vector3 currentPointPosition =
                generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i]);
            if (i == 0)
            {
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                float distanceBetweenPoints = Vector3.Distance(nextPointPosition, currentPointPosition);
                distanceBetweenPoints = distanceBetweenPoints * 0.8f;
                tangentLS = (nextPointPosition - currentPointPosition).normalized * 0.2f;distanceBetweenPoints;
            }
            else if (i < ropeSaveData.ropeCurvePoints.Count - 1)
            {
                Vector3 previousPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i - 1]);
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                float distanceBetweenPoints = Vector3.Distance(nextPointPosition, currentPointPosition);
                distanceBetweenPoints = distanceBetweenPoints * 0.8f;
                tangentLS = (nextPointPosition - previousPointPosition).normalized * 0.2f;distanceBetweenPoints;
            }

            // Build the rope path:
            blueprint.path.AddControlPoint(currentPointPosition, -tangentLS, tangentLS, Vector3.up,
                0.1f, 0.1f, 1, filter, Color.white, "start_" + i);
        }

So with help of @DMGregory. I made it work with the following code.

Vector3 tangentLS = default;
        for (int i = 0; i < ropeSaveData.ropeCurvePoints.Count; i++)
        {
            // Calculate control point positions and tangent vector:
            Vector3 currentPointPosition =
                generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i]);
            if (i == 0)
            {
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                tangentLS = (nextPointPosition - currentPointPosition).normalized * 0.2f;
            }
            else if (i < ropeSaveData.ropeCurvePoints.Count - 1)
            {
                Vector3 previousPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i - 1]);
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                tangentLS = (nextPointPosition - previousPointPosition).normalized * 0.2f;
            }

            // Build the rope path:
            blueprint.path.AddControlPoint(currentPointPosition, -tangentLS, tangentLS, Vector3.up,
                0.1f, 0.1f, 1, filter, Color.white, "start_" + i);
        }

Thank you @DMGregory for pointing me out in the right direction.

So earlier I was just normalizing the tangents with length 1 which was creating problems since as I mentioned in the question that tangent length affects the curvature of the path so I modified that by reducing the length of the tangents, proportionally to the distance between points. distanceBetweenPoints is the one that corrects the tangent length.

Now it is working perfectly fine. Here's the updated code:

Vector3 tangentLS = default;
        for (int i = 0; i < ropeSaveData.ropeCurvePoints.Count; i++)
        {
            // Calculate control point positions and tangent vector:
            Vector3 currentPointPosition =
                generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i]);
            if (i == 0)
            {
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                float distanceBetweenPoints = Vector3.Distance(nextPointPosition, currentPointPosition);
                distanceBetweenPoints = distanceBetweenPoints * 0.8f;
                tangentLS = (nextPointPosition - currentPointPosition).normalized * distanceBetweenPoints;
            }
            else if (i < ropeSaveData.ropeCurvePoints.Count - 1)
            {
                Vector3 previousPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i - 1]);
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                float distanceBetweenPoints = Vector3.Distance(nextPointPosition, currentPointPosition);
                distanceBetweenPoints = distanceBetweenPoints * 0.8f;
                tangentLS = (nextPointPosition - previousPointPosition).normalized * distanceBetweenPoints;
            }

            // Build the rope path:
            blueprint.path.AddControlPoint(currentPointPosition, -tangentLS, tangentLS, Vector3.up,
                0.1f, 0.1f, 1, filter, Color.white, "start_" + i);
        }
Source Link

So with help of @DMGregory. I made it work with the following code.

Vector3 tangentLS = default;
        for (int i = 0; i < ropeSaveData.ropeCurvePoints.Count; i++)
        {
            // Calculate control point positions and tangent vector:
            Vector3 currentPointPosition =
                generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i]);
            if (i == 0)
            {
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                tangentLS = (nextPointPosition - currentPointPosition).normalized * 0.2f;
            }
            else if (i < ropeSaveData.ropeCurvePoints.Count - 1)
            {
                Vector3 previousPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i - 1]);
                Vector3 nextPointPosition =
                    generatedRope.transform.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                tangentLS = (nextPointPosition - previousPointPosition).normalized * 0.2f;
            }

            // Build the rope path:
            blueprint.path.AddControlPoint(currentPointPosition, -tangentLS, tangentLS, Vector3.up,
                0.1f, 0.1f, 1, filter, Color.white, "start_" + i);
        }