protected virtual void Update()
        {
            IMoveX bodyMoveX = body as IMoveX;
            IMoveY bodyMoveY = body as IMoveY;
            IMoveZ bodyMoveZ = body as IMoveZ;
            ITwist bodyTwist = body as ITwist;
            IJump  bodyJump  = body as IJump;

            if (bodyJump != null)
            {
                if (Input.GetButtonDown(jumpButtonName))
                {
                    bodyJump.JumpBegin();
                }
                else if (Input.GetButtonUp(jumpButtonName))
                {
                    bodyJump.JumpEnd();
                }
            }

            if (bodyMoveX != null)
            {
                bodyMoveX.MoveX(Input.GetAxis(xAxisName));
            }

            if (bodyMoveY != null)
            {
                bodyMoveY.MoveY(Input.GetAxis(yAxisName));
            }

            if (bodyMoveZ != null)
            {
                if (Input.GetAxis(zAxisName) < 0f)
                {
                    int x = 1;
                    x += 1;
                }

                bodyMoveZ.MoveZ(Input.GetAxis(zAxisName));
            }

            if (bodyTwist != null)
            {
                bodyTwist.Twist(Input.GetAxis(twistAxisName) * Time.deltaTime * maxTwistSpeed);
            }
        }
Пример #2
0
        protected virtual void Update()
        {
            IMoveX bodyMoveX = body as IMoveX;
            IMoveY bodyMoveY = body as IMoveY;
            IMoveZ bodyMoveZ = body as IMoveZ;
            ITwist bodyTwist = body as ITwist;
            IJump  bodyJump  = body as IJump;

            // For the sake of following the target, we need to see if they're
            // distant from us. This is going to be a pretty dumb follow
            // function and doesn't care how high-up they are. Thus, we will
            // project both our position and the target's position onto the
            // same plane. Then any heigh-difference gets ignored.
            //
            // If needed, we could also calculate the height pretty easily.
            // Just take the difference of the actual positions with their
            // respective projected positions, and these are their heights
            // relative to the plane. With this knowledge, we could calculate
            // the height relative to one another.
            Vector3 currentProjectedPos = Vector3.ProjectOnPlane(transform.position, transform.up);
            Vector3 targetProjectedPos  = Vector3.ProjectOnPlane(target.position, transform.up);

            if ((targetProjectedPos - currentProjectedPos).sqrMagnitude > maxDist * maxDist)
            {
                if (bodyMoveZ != null)
                {
                    walkingSpeed = Mathf.Clamp01(walkingSpeed + Time.deltaTime);
                    bodyMoveZ.MoveZ(walkingSpeed);
                }

                if (bodyTwist != null)
                {
                    bodyTwist.TwistToward(target.position);
                }
            }
            else
            {
                walkingSpeed = 0f;
            }
        }