Example #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()
        {
            // If the movement controller itself is disabled, this shouldn't run.
            if (!enabled)
            {
                return;
            }

            // Move the player by our velocity every frame.
            transform.position += currentVelocity * superCharacterController.deltaTime;

            // If alive and is moving, set animator.
            if (!rpgCharacterController.isDead && rpgCharacterController.canMove)
            {
                if (currentVelocity.magnitude > 0f)
                {
                    animator.SetFloat("Velocity X", 0);
                    animator.SetFloat("Velocity Z", transform.InverseTransformDirection(currentVelocity).z *movementAnimationMultiplier);
                    animator.SetBool("Moving", true);
                }
                else
                {
                    animator.SetFloat("Velocity X", 0f);
                    animator.SetFloat("Velocity Z", 0f);
                    animator.SetBool("Moving", false);
                }
            }
            // Aiming.
            if (rpgCharacterController.isAiming || rpgCharacterController.isStrafing)
            {
                Strafing(rpgCharacterController.aimInput);
            }

            // Facing.
            else if (rpgCharacterController.isFacing)
            {
                Facing(rpgCharacterController.faceInput);
            }
            else if (rpgCharacterController.canMove)
            {
                RotateTowardsMovementDir();
            }

            if (currentState == null && rpgCharacterController.CanStartAction("Idle"))
            {
                rpgCharacterController.StartAction("Idle");
            }

            // Update animator with local movement values.
            animator.SetFloat("Velocity X", transform.InverseTransformDirection(currentVelocity).x *movementAnimationMultiplier);
            animator.SetFloat("Velocity Z", transform.InverseTransformDirection(currentVelocity).z *movementAnimationMultiplier);
        }
 void Update()
 {
     if (character != null)
     {
         RPGCharacterController controller = character.GetComponent <RPGCharacterController>();
         controller.SetJumpInput(Vector3.up);
         if (controller.CanStartAction("Jump"))
         {
             controller.StartAction("Jump");
         }
     }
 }
        /// <summary>
        /// Input abstraction for easier asset updates using outside control schemes.
        /// </summary>
        private void Inputs()
        {
            try {
                inputAttackL     = rpgInputs.RPGCharacter.AttackL.WasPressedThisFrame();
                inputAttackR     = rpgInputs.RPGCharacter.AttackR.WasPressedThisFrame();
                inputBlock       = rpgInputs.RPGCharacter.Block.IsPressed();
                inputCastL       = rpgInputs.RPGCharacter.CastL.WasPressedThisFrame();
                inputCastR       = rpgInputs.RPGCharacter.CastR.WasPressedThisFrame();
                inputDeath       = rpgInputs.RPGCharacter.Death.WasPressedThisFrame();
                inputFace        = rpgInputs.RPGCharacter.Face.IsPressed();
                inputFacing      = rpgInputs.RPGCharacter.Facing.ReadValue <Vector2>();
                inputJump        = rpgInputs.RPGCharacter.Jump.WasPressedThisFrame();
                inputLightHit    = rpgInputs.RPGCharacter.LightHit.WasPressedThisFrame();
                inputMovement    = rpgInputs.RPGCharacter.Move.ReadValue <Vector2>();
                inputRelax       = rpgInputs.RPGCharacter.Relax.WasPressedThisFrame();
                inputRoll        = rpgInputs.RPGCharacter.Roll.WasPressedThisFrame();
                inputShield      = rpgInputs.RPGCharacter.Shield.WasPressedThisFrame();
                inputAim         = rpgInputs.RPGCharacter.Aim.IsPressed();
                inputSwitchDown  = rpgInputs.RPGCharacter.WeaponDown.WasPressedThisFrame();
                inputSwitchLeft  = rpgInputs.RPGCharacter.WeaponLeft.WasPressedThisFrame();
                inputSwitchRight = rpgInputs.RPGCharacter.WeaponRight.WasPressedThisFrame();
                inputSwitchUp    = rpgInputs.RPGCharacter.WeaponUp.WasPressedThisFrame();

                // Injury toggle.
                if (Keyboard.current.iKey.wasPressedThisFrame)
                {
                    if (rpgCharacterController.CanStartAction("Injure"))
                    {
                        rpgCharacterController.StartAction("Injure");
                    }
                    else if (rpgCharacterController.CanEndAction("Injure"))
                    {
                        rpgCharacterController.EndAction("Injure");
                    }
                }
                // Headlook toggle.
                if (Keyboard.current.lKey.wasPressedThisFrame)
                {
                    rpgCharacterController.ToggleHeadlook();
                }
                // Slow time toggle.
                if (Keyboard.current.tKey.wasPressedThisFrame)
                {
                    if (rpgCharacterController.CanStartAction("SlowTime"))
                    {
                        rpgCharacterController.StartAction("SlowTime", 0.125f);
                    }
                    else if (rpgCharacterController.CanEndAction("SlowTime"))
                    {
                        rpgCharacterController.EndAction("SlowTime");
                    }
                }
                // Pause toggle.
                if (Keyboard.current.pKey.wasPressedThisFrame)
                {
                    if (rpgCharacterController.CanStartAction("SlowTime"))
                    {
                        rpgCharacterController.StartAction("SlowTime", 0f);
                    }
                    else if (rpgCharacterController.CanEndAction("SlowTime"))
                    {
                        rpgCharacterController.EndAction("SlowTime");
                    }
                }
            } catch (System.Exception) { Debug.LogError("Inputs not found!  Character must have Player Input component."); }
        }
Example #4
0
 private void Sprinting()
 {
     if (rpgCharacterController.hasNoWeapon)
     {
         bool useSprint = GUI.Toggle(new Rect(640, 115, 100, 30), rpgCharacterController.isSprinting, "Sprint");
         if (useSprint && rpgCharacterController.CanStartAction("Sprint"))
         {
             rpgCharacterController.StartAction("Sprint");
         }
         else if (!useSprint && rpgCharacterController.CanEndAction("Sprint"))
         {
             rpgCharacterController.EndAction("Sprint");
         }
     }
 }
Example #5
0
        /// <summary>
        /// Input abstraction for easier asset updates using outside control schemes.
        /// </summary>
        private void Inputs()
        {
            try {
                inputJump             = Input.GetButtonDown("Jump");
                isJumpHeld            = Input.GetButton("Jump");
                inputLightHit         = Input.GetButtonDown("LightHit");
                inputDeath            = Input.GetButtonDown("Death");
                inputAttackL          = Input.GetButtonDown("AttackL");
                inputAttackR          = Input.GetButtonDown("AttackR");
                inputCastL            = Input.GetButtonDown("CastL");
                inputCastR            = Input.GetButtonDown("CastR");
                inputSwitchUpDown     = Input.GetAxisRaw("SwitchUpDown");
                inputSwitchLeftRight  = Input.GetAxisRaw("SwitchLeftRight");
                inputAimBlock         = Input.GetAxisRaw("Aim");
                inputAiming           = Input.GetButton("Aiming");
                inputHorizontal       = Input.GetAxisRaw("Horizontal");
                inputVertical         = Input.GetAxisRaw("Vertical");
                inputFace             = Input.GetMouseButton(1);
                inputFacingHorizontal = Input.GetAxisRaw("FacingHorizontal");
                inputFacingVertical   = Input.GetAxisRaw("FacingVertical");
                inputRoll             = Input.GetButtonDown("L3");
                inputShield           = Input.GetButtonDown("Shield");
                inputRelax            = Input.GetButtonDown("Relax");

                // Injury toggle.
                if (Input.GetKeyDown(KeyCode.I))
                {
                    if (rpgCharacterController.CanStartAction("Injure"))
                    {
                        rpgCharacterController.StartAction("Injure");
                    }
                    else if (rpgCharacterController.CanEndAction("Injure"))
                    {
                        rpgCharacterController.EndAction("Injure");
                    }
                }
                // Headlook toggle.
                if (Input.GetKeyDown(KeyCode.L))
                {
                    rpgCharacterController.ToggleHeadlook();
                }

                // Slow time toggle.
                if (Input.GetKeyDown(KeyCode.T))
                {
                    if (rpgCharacterController.CanStartAction("SlowTime"))
                    {
                        rpgCharacterController.StartAction("SlowTime", 0.125f);
                    }
                    else if (rpgCharacterController.CanEndAction("SlowTime"))
                    {
                        rpgCharacterController.EndAction("SlowTime");
                    }
                }
                // Pause toggle.
                if (Input.GetKeyDown(KeyCode.P))
                {
                    if (rpgCharacterController.CanStartAction("SlowTime"))
                    {
                        rpgCharacterController.StartAction("SlowTime", 0f);
                    }
                    else if (rpgCharacterController.CanEndAction("SlowTime"))
                    {
                        rpgCharacterController.EndAction("SlowTime");
                    }
                }
            } catch (System.Exception) { Debug.LogError("Inputs not found!"); }
        }