public static void Test()
        {
            float[] values = { 0f, 1f, 2f, 3f, 4f };

            var interpolation = new CatmullRomSpline(values);

            Debug.Log(interpolation.GetValue(-1f));
            Debug.Log(interpolation.GetValue(3.5f));
            Debug.Log(interpolation.GetValue(4f));
            Debug.Log(interpolation.GetValue(5f));
        }
示例#2
0
        void Start()
        {
            fragments[0].transform.position = transform.position;

            var lineRenderer = GetComponent <LineRenderer>();

            lineRenderer.positionCount = (fragmentCount - 1) * splineFactor + 1;

            xPositions = new float[fragments.Length];
            yPositions = new float[fragments.Length];
            zPositions = new float[fragments.Length];

            splineX = new CatmullRomSpline(xPositions);
            splineY = new CatmullRomSpline(yPositions);
            splineZ = new CatmullRomSpline(zPositions);
        }
示例#3
0
        //public bool isConnected = false;

        void Start()
        {
            activeFragmentCount = fragmentCount;

            fragments = new GameObject[fragmentCount];

            //var position = Vector3.zero;
            Vector3 position = transform.position;

            // Set fragments as child of the Rope object, and leave 'interval' amount of distance between them
            for (int i = 0; i < fragmentCount; i++)
            {
                fragments[i] = Instantiate(fragmentPrefab, position, Quaternion.identity);
                fragments[i].transform.SetParent(transform);

                SpringJoint joint = fragments[i].GetComponent <SpringJoint>();
                if (i > 0)
                {
                    joint.connectedBody = fragments[i - 1].GetComponent <Rigidbody>();
                }

                position += interval;
            }

            LineRenderer lineRenderer = GetComponent <LineRenderer>();

            lineRenderer.positionCount = (fragmentCount - 1) * splineFactor + 1;

            xPositions = new float[fragmentCount];
            yPositions = new float[fragmentCount];
            zPositions = new float[fragmentCount];

            splineX = new CatmullRomSpline(xPositions);
            splineY = new CatmullRomSpline(yPositions);
            splineZ = new CatmullRomSpline(zPositions);
        }