SebLague / Path-Creator

Path creation asset for Unity game development
https://assetstore.unity.com/packages/tools/utilities/b-zier-path-creator-136082
MIT License
1.83k stars 319 forks source link

Anchor & Control Points #137

Closed shemtomke closed 1 year ago

shemtomke commented 1 year ago

using this set of code i get different positions as per the anchor points in the path creator: (I used NumAnchorPoints)

for (int i = 0; i < pathCreator[currentPathCreator].bezierPath.NumAnchorPoints; i++)
        {
            Debug.Log("POINT " + i + " : " + pathCreator[currentPathCreator].bezierPath.GetPoint(i));
        }

From the Highlighted Point we see it does not match the anchor point (Anchor Index 1) vector 3 position. This is also an issues to other points in the path.

They do not match at all! DEBUG LOG MESSAGE FOR ANCHOR POINT 1 - POINT 1 : (-8.31, -4.47, 0.00) INSPECTOR PATH CREATOR ANCHOR POINT 1 - (-7.691796, -4.233789, 0)

Screenshot 2023-05-05 115304

I noticed some of the values fetched/debugged are from the control points rather from the anchor points. This was with the help of this code to verify. (I used NumPoints)

for (int i = 0; i < pathCreator[currentPathCreator].bezierPath.NumPoints; i++)
        {
            Debug.Log("POINT " + i + " : " + pathCreator[currentPathCreator].bezierPath.GetPoint(i));
        }

How do I go about this issue?

shemtomke commented 1 year ago

I changed the for loop to this and i was able to get the exact position of the anchor points

for (int i = 0; i < pathCreator[currentPathCreator].bezierPath.NumAnchorPoints; i++)
        {
            Debug.Log("POINT " + i + " : " + pathCreator[currentPathCreator].bezierPath.GetPoint(i*3));
        }

The GetPoint method takes the i and multiplied by 3 because for each two anchor points holds the position of 2 control points in between. When we start from 0 as an anchor index we are able to get the the second index (1) from the difference of 2 control points in between. So essentially is 0*3 to get second Anchor index.