コード例 #1
0
 public IEnumerator _EnterParadise()
 {
     rpgCharacterState = RPGCharacterState.CINEMATIC;
     animator.SetBool("Moving", true);
     animator.SetFloat("Velocity Z", 0.5f);
     yield break;
 }
コード例 #2
0
 public void SetModeCinematic()
 {
     rpgCharacterState = RPGCharacterState.CINEMATIC;
     weapon            = 0;
     animator.SetTrigger("RelaxTrigger");
     animator.SetBool("Relax", true);
 }
コード例 #3
0
        private void Start()
        {
            //Get other RPG Character components.
            superCharacterController    = GetComponent <SuperCharacterController>();
            rpgCharacterController      = GetComponent <RPGCharacterControllerFREE>();
            rpgCharacterInputController = GetComponent <RPGCharacterInputControllerFREE>();
            navMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent>();

            //Check if Animator exists, otherwise pause script.
            animator = GetComponentInChildren <Animator>();
            if (animator == null)
            {
                Destroy(this);
                return;
            }

            //Setup Collider and Rigidbody for collisions.
            capCollider = GetComponent <CapsuleCollider>();
            rb          = GetComponent <Rigidbody>();
            if (rb != null)
            {
                //Set restraints on startup if using Rigidbody.
                rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
            }

            SwitchCollisionOn();

            //Set currentState to idle on startup.
            currentState      = RPGCharacterState.Idle;
            rpgCharacterState = RPGCharacterState.Idle;
        }
コード例 #4
0
 private void OnTriggerExit(Collider collide)
 {
     //Leaving a water volume.
     if (collide.gameObject.layer == 4)
     {
         animator.SetBool("Swimming", false);
         currentState      = RPGCharacterState.Jump;
         rpgCharacterState = RPGCharacterState.Jump;
     }
     //Leaving a ladder.
     else if (collide.transform.parent != null)
     {
         if (collide.transform.parent.name.Contains("Ladder"))
         {
             rpgCharacterController.isNearLadder = false;
             rpgCharacterController.ladder       = null;
         }
     }
     //leaving a cliff.
     else if (collide.transform.name.Contains("Cliff"))
     {
         rpgCharacterController.isNearCliff = false;
         rpgCharacterController.cliff       = null;
     }
 }
コード例 #5
0
 private void Move_SuperUpdate()
 {
     //If Jump.
     if (rpgCharacterInputController.allowedInput && rpgCharacterInputController.inputJump)
     {
         currentState      = RPGCharacterState.Jump;
         rpgCharacterState = RPGCharacterState.Jump;
         return;
     }
     //Falling.
     if (!MaintainingGround())
     {
         currentState      = RPGCharacterState.Fall;
         rpgCharacterState = RPGCharacterState.Fall;
         return;
     }
     //Set speed determined by movement type.
     if (rpgCharacterInputController.HasMoveInput() && canMove)
     {
         //Keep strafing animations from playing.
         animator.SetFloat("Velocity X", 0F);
         //Injured limp.
         if (rpgCharacterController.injured)
         {
             currentVelocity = Vector3.MoveTowards(currentVelocity, rpgCharacterInputController.moveInput * 1.35f, movementAcceleration * superCharacterController.deltaTime);
             return;
         }
         //Sprinting.
         if (isSprinting)
         {
             currentVelocity = Vector3.MoveTowards(currentVelocity, rpgCharacterInputController.moveInput * sprintSpeed, movementAcceleration * superCharacterController.deltaTime);
             return;
         }
         //Strafing or Walking.
         if (rpgCharacterController.isStrafing)
         {
             currentVelocity = Vector3.MoveTowards(currentVelocity, rpgCharacterInputController.moveInput * walkSpeed, movementAcceleration * superCharacterController.deltaTime);
             if (rpgCharacterController.weapon != Weapon.RELAX)
             {
                 Strafing(rpgCharacterController.target.transform.position);
             }
             return;
         }
         //Run.
         currentVelocity = Vector3.MoveTowards(currentVelocity, rpgCharacterInputController.moveInput * runSpeed, movementAcceleration * superCharacterController.deltaTime);
     }
     else
     {
         currentState      = RPGCharacterState.Idle;
         rpgCharacterState = RPGCharacterState.Idle;
         return;
     }
 }
コード例 #6
0
 private void Fall_SuperUpdate()
 {
     if (AcquiringGround())
     {
         currentVelocity   = Math3d.ProjectVectorOnPlane(superCharacterController.up, currentVelocity);
         currentState      = RPGCharacterState.Idle;
         rpgCharacterState = RPGCharacterState.Idle;
         return;
     }
     DoubleJump();
     currentVelocity -= superCharacterController.up * gravity * superCharacterController.deltaTime;
 }
コード例 #7
0
 private void DoubleJump()
 {
     if (!doublejumped)
     {
         canDoubleJump = true;
     }
     if (rpgCharacterInputController.inputJump && canDoubleJump && !doublejumped)
     {
         currentState      = RPGCharacterState.DoubleJump;
         rpgCharacterState = RPGCharacterState.DoubleJump;
     }
 }
コード例 #8
0
        /// <summary>
        /// Character Roll.
        /// </summary>
        /// <param name="1">Forward.</param>
        /// <param name="2">Right.</param>
        /// <param name="3">Backward.</param>
        /// <param name="4">Left.</param>
        public IEnumerator _Roll(int roll)
        {
            rollNumber        = roll;
            currentState      = RPGCharacterState.Roll;
            rpgCharacterState = RPGCharacterState.Roll;
            animator.SetInteger("Action", rollNumber);
            animator.SetTrigger("RollTrigger");
            isRolling = true;
            rpgCharacterController.Lock(true, true, true, 0, rollduration);
            yield return(new WaitForSeconds(rollduration));

            isRolling         = false;
            currentState      = RPGCharacterState.Idle;
            rpgCharacterState = RPGCharacterState.Idle;
        }
コード例 #9
0
 void Awake()
 {
     superCharacterController    = GetComponent <SuperCharacterController>();
     rpgCharacterController      = GetComponent <RPGCharacterControllerFREE>();
     rpgCharacterInputController = GetComponent <RPGCharacterInputController>();
     navMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent>();
     animator     = GetComponentInChildren <Animator>();
     rb           = GetComponent <Rigidbody>();
     if (rb != null)
     {
         //Set restraints on startup if using Rigidbody.
         rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
     }
     //Set currentState to idle on startup.
     currentState      = RPGCharacterState.Idle;
     rpgCharacterState = RPGCharacterState.Idle;
 }
コード例 #10
0
        private void Jump_SuperUpdate()
        {
            Vector3 planarMoveDirection   = Math3d.ProjectVectorOnPlane(superCharacterController.up, currentVelocity);
            Vector3 verticalMoveDirection = currentVelocity - planarMoveDirection;

            //Falling.
            if (currentVelocity.y < 0)
            {
                currentVelocity   = planarMoveDirection;
                currentState      = RPGCharacterState.Fall;
                rpgCharacterState = RPGCharacterState.Fall;
                return;
            }
            planarMoveDirection    = Vector3.MoveTowards(planarMoveDirection, rpgCharacterInputController.moveInput * inAirSpeed, jumpAcceleration * superCharacterController.deltaTime);
            verticalMoveDirection -= superCharacterController.up * gravity * superCharacterController.deltaTime;
            currentVelocity        = planarMoveDirection + verticalMoveDirection;
        }
コード例 #11
0
 private void Awake()
 {
     //superCharacterController = GetComponent<SuperCharacterController>();
     rpgCharacterController      = GetComponent <RPGCharacterController>();
     rpgCharacterInputController = GetComponent <RPGCharacterInputController>();
     animator    = GetComponentInChildren <Animator>();
     capCollider = GetComponent <CapsuleCollider>();
     rb          = GetComponent <Rigidbody>();
     if (rb != null)
     {
         //Set restraints on startup if using Rigidbody.
         rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
     }
     //Set currentState to idle on startup.
     currentState      = RPGCharacterState.Idle;
     rpgCharacterState = RPGCharacterState.Idle;
 }
コード例 #12
0
        /// <summary>
        /// Character Roll.
        /// </summary>
        /// <param name="1">Forward.</param>
        /// <param name="2">Right.</param>
        /// <param name="3">Backward.</param>
        /// <param name="4">Left.</param>
        public IEnumerator _Roll(int roll)
        {
            rollNumber        = roll;
            currentState      = RPGCharacterState.Roll;
            rpgCharacterState = RPGCharacterState.Roll;
            if (rpgCharacterController.weapon == Weapon.RELAX)
            {
                rpgCharacterController.weapon = Weapon.UNARMED;
                animator.SetInteger("Weapon", 0);
            }
            animator.SetInteger("Action", rollNumber);
            animator.SetTrigger("RollTrigger");
            isRolling = true;
            rpgCharacterController.canAction = false;
            yield return(new WaitForSeconds(rollduration));

            isRolling = false;
            rpgCharacterController.canAction = true;
            currentState      = RPGCharacterState.Idle;
            rpgCharacterState = RPGCharacterState.Idle;
        }
コード例 #13
0
        private void Jump_SuperUpdate()
        {
            Vector3 planarMoveDirection   = Math3d.ProjectVectorOnPlane(superCharacterController.up, currentVelocity);
            Vector3 verticalMoveDirection = currentVelocity - planarMoveDirection;

            if (Vector3.Angle(verticalMoveDirection, superCharacterController.up) > 90 && AcquiringGround())
            {
                currentVelocity   = planarMoveDirection;
                currentState      = RPGCharacterState.Idle;
                rpgCharacterState = RPGCharacterState.Idle;
                return;
            }
            planarMoveDirection    = Vector3.MoveTowards(planarMoveDirection, LocalMovement() * inAirSpeed, jumpAcceleration * superCharacterController.deltaTime);
            verticalMoveDirection -= superCharacterController.up * gravity * superCharacterController.deltaTime;
            currentVelocity        = planarMoveDirection + verticalMoveDirection;
            //Can double jump if starting to fall.
            if (currentVelocity.y < 0)
            {
                DoubleJump();
            }
        }
コード例 #14
0
 void Move_SuperUpdate()
 {
     //If Jump.
     if (rpgCharacterInputController.current.jumpInput)
     {
         currentState      = RPGCharacterState.Jump;
         rpgCharacterState = RPGCharacterState.Jump;
         return;
     }
     if (!MaintainingGround())
     {
         currentState      = RPGCharacterState.Fall;
         rpgCharacterState = RPGCharacterState.Fall;
         return;
     }
     //Set speed determined by movement type.
     if (rpgCharacterInputController.HasMoveInput() && canMove)
     {
         //Keep strafing animations from playing.
         animator.SetFloat("Velocity X", 0F);
         //Strafing or Walking.
         if (rpgCharacterController.isStrafing)
         {
             currentVelocity = Vector3.MoveTowards(currentVelocity, LocalMovement() * walkSpeed, movementAcceleration * superCharacterController.deltaTime);
             Strafing(rpgCharacterController.target.transform.position);
             return;
         }
         //Run.
         currentVelocity = Vector3.MoveTowards(currentVelocity, LocalMovement() * runSpeed, movementAcceleration * superCharacterController.deltaTime);
     }
     else
     {
         currentState      = RPGCharacterState.Idle;
         rpgCharacterState = RPGCharacterState.Idle;
         return;
     }
 }
コード例 #15
0
 private void OnTriggerEnter(Collider collide)
 {
     //Entering a water volume.
     if (collide.gameObject.layer == 4)
     {
         currentState      = RPGCharacterState.Swim;
         rpgCharacterState = RPGCharacterState.Swim;
     }
     //Near a ladder.
     else if (collide.transform.parent != null)
     {
         if (collide.transform.parent.name.Contains("Ladder"))
         {
             rpgCharacterController.isNearLadder = true;
             rpgCharacterController.ladder       = collide.gameObject;
         }
     }
     //Near a cliff.
     else if (collide.transform.name.Contains("Cliff"))
     {
         rpgCharacterController.isNearCliff = true;
         rpgCharacterController.cliff       = collide.gameObject;
     }
 }
コード例 #16
0
 //Run every frame we are in the idle state.
 private void Idle_SuperUpdate()
 {
     //If Jump.
     if (rpgCharacterInputController.allowedInput && rpgCharacterInputController.inputJump)
     {
         currentState      = RPGCharacterState.Jump;
         rpgCharacterState = RPGCharacterState.Jump;
         return;
     }
     if (!MaintainingGround())
     {
         currentState      = RPGCharacterState.Fall;
         rpgCharacterState = RPGCharacterState.Fall;
         return;
     }
     if (rpgCharacterInputController.HasMoveInput() && canMove)
     {
         currentState      = RPGCharacterState.Move;
         rpgCharacterState = RPGCharacterState.Move;
         return;
     }
     //Apply friction to slow to a halt.
     currentVelocity = Vector3.MoveTowards(currentVelocity, Vector3.zero, groundFriction * superCharacterController.deltaTime);
 }
コード例 #17
0
 public void SetModeDefault()
 {
     rpgCharacterState = RPGCharacterState.DEFAULT;
     Sword();
 }