Esempio n. 1
0
    // Put given cell on on cell along given value
    public void PutOnSkeleton(Transform prefab, float distance)
    {
        // Get data where certain point on skeleton is absolute to world
        SkeletonPointData point = skeleton.GetPointOnSkeleton(distance);

        // Apply data
        prefab.position = point.position;
        prefab.rotation = point.rotation;
    }
Esempio n. 2
0
//////////////////////////////////////////////////////// EO TRIM METHODS //



// GET DATA ALONG SKELETON ////////////////////////////////////////////////////////

    public SkeletonPointData GetPointOnSkeleton(float input)
    {
        if (input > Math.Round(length, GameManager.ROUND_DECIMALS))
        {
            throw new System.ArgumentException("Input is larger than skeleton length! (" + input + ")");
        }
        else if (input < 0)
        {
            throw new System.ArgumentException("Input is negative! (" + input + ")");
        }

        SkeletonPointData data = new SkeletonPointData();

        float traversed = 0;            ///< How far algorithem travesed until current step

        for (int i = 0; i < joints.Count - 1; i++)
        {
            // Get current bone
            Vector3 a    = joints[i];
            Vector3 b    = joints[i + 1];
            Vector3 bone = b - a;

            traversed += bone.magnitude;

            if (traversed >= input)
            {
                float remaining = bone.magnitude - (traversed - input);

                data.position = a + bone.normalized * remaining;
                data.rotation = Quaternion.LookRotation(a - b);

                return(data);
            }
        }

        return(data);
    }