예제 #1
0
    private void InsertNewPoint()
    {
        if (selectedIndex < 0 || selectedIndex >= spline.Count)
        {
            return;
        }

        if (spline.Count == 0)
        {
            AddNewPoint();
        }
        else
        {
            Vector2 pos = Vector2.zero;
            if (selectedIndex == 0)
            {
                // Insert at start
                // If nothing to project, just down & left
                if (spline.Count == 1)
                {
                    pos = spline.GetPoint(0) - Vector2.up * 2.0f - Vector2.right * 2.0f;
                }
                else
                {
                    // Extended from  previous & varied a little
                    // rotate left/right alternately for interest
                    Vector2 tangent = spline.Derivative(0);
                    pos = spline.GetPoint(0) - tangent * 2f;
                }
            }
            else
            {
                // split half way between previous and selected
                pos = spline.Interpolate(selectedIndex - 1, 0.5f);
            }

            spline.InsertPoint(selectedIndex, pos);
        }
    }
예제 #2
0
    protected override void Update()
    {
        if (!IsAlive)
        {
            bossDoor.gameObject.SetActive(false);
        }

        base.Update();

        if (awake)
        {
            pathPosition += speed * Time.deltaTime;
        }

        pathPosition = Mathf.Repeat(pathPosition, path.Length);

        float t = path.DistanceToLinearT(pathPosition);

        transform.position = path.transform.TransformPoint(path.Interpolate(t));
        Vector3 derivative = path.transform.TransformDirection(path.Derivative(t));

        transform.rotation = Quaternion.LookRotation(Vector3.forward, new Vector3(derivative.y, -derivative.x));
    }