Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (enemyController.freezeEnemy)
        {
            // add anything here to happen while frozen i.e. time compensations
            // path start time for bezier curve gets annihilated when frozen - compensate
            pathTimeStart += Time.deltaTime;
            return;
        }

        // do Pepe ai logic if it's enabled
        if (enableAI)
        {
            // play animation
            animator.Play("Pepe_Flying");

            // calculate next travel path when previous is completed
            if (!isFollowingPath)
            {
                // distance/length to the next end point, get start point from rigidbody position,
                // end point is calculated by adding the distance to start point
                // middle point is calculated and the height is applied to form the curve
                // start time is needed to determine the point in the curve we want
                // i.e. this is just like LERPing
                float distance = (isFacingRight) ? bezierDistance : -bezierDistance;
                pathStartPoint  = rb2d.transform.position;
                pathEndPoint    = new Vector3(pathStartPoint.x + distance, pathStartPoint.y, pathStartPoint.z);
                pathMidPoint    = pathStartPoint + (((pathEndPoint - pathStartPoint) / 2) + bezierHeight);
                pathTimeStart   = Time.time;
                isFollowingPath = true;
            }
            else
            {
                // percentage is the point in the curve we want and update our rigidbody position
                float percentage = (Time.time - pathTimeStart) / bezierTime;
                rb2d.transform.position = UtilityFunctions.CalculateQuadraticBezierPoint(pathStartPoint, pathMidPoint, pathEndPoint, percentage);
                // end of the curve has been reach
                if (percentage >= 1f)
                {
                    // invert the height - this is what creates the flying wave effect
                    bezierHeight   *= -1;
                    isFollowingPath = false;
                }
            }
        }
    }