예제 #1
0
        //Put any code in here you want to run AFTER the state's update function.  This is run regardless of what state you're in.
        protected override void LateGlobalSuperUpdate()
        {
            //Move the player by our velocity every frame.
            transform.position += currentVelocity * superCharacterController.deltaTime;
            //If using Navmesh nagivation, update values.
            if (navMeshAgent != null)
            {
                if (useMeshNav)
                {
                    if (navMeshAgent.velocity.sqrMagnitude > 0)
                    {
                        animator.SetBool("Moving", true);
                        animator.SetFloat("Velocity Z", navMeshAgent.velocity.magnitude);
                        return;
                    }
                    else
                    {
                        animator.SetFloat("Velocity Z", 0);
                    }
                }
            }
            //If alive and is moving, set animator.
            if (!useMeshNav && !rpgCharacterController.isDead && canMove)
            {
                if (currentVelocity.magnitude > 0 && rpgCharacterInputController.HasMoveInput())
                {
                    isMoving = true;
                    animator.SetBool("Moving", true);
                    animator.SetFloat("Velocity Z", currentVelocity.magnitude);
                }
                else
                {
                    isMoving = false;
                    animator.SetBool("Moving", false);
                }
            }
            //Rotate towards movement direction.
            if (!rpgCharacterController.isTargeting || rpgCharacterController.injured)
            {
                if (rpgCharacterInputController.HasMoveInput() && canMove)
                {
                    RotateTowardsMovementDir();
                }
            }
            //Otherwise rotate towards Target.(strafing)
            else
            {
                RotateTowardsTarget(rpgCharacterController.target.transform.position);
            }

            animator.SetFloat("Velocity X", transform.InverseTransformDirection(currentVelocity).x);
            animator.SetFloat("Velocity Z", transform.InverseTransformDirection(currentVelocity).z);
        }