コード例 #1
0
 private void Inputs()
 {
     if (Input.GetKey(KeyCode.Space) && _isGrounded)
     {
         _isJumping = true;
         Jump?.Invoke();
     }
     if (Input.GetKeyDown(KeyCode.LeftShift) && !_beganFall && _isMoving)
     {
         _isSprinting = true;
         Sprint?.Invoke();
     }
     if (Input.GetKeyUp(KeyCode.LeftShift) && !_beganFall)
     {
         _isSprinting = false;
         if (_isMoving)
         {
             StartRunning?.Invoke();
         }
         else
         {
             Idle?.Invoke();
         }
     }
     if (Input.GetKeyDown(KeyCode.Mouse0) && !cooldown)
     {
         loadout.UseEquppiedAbility(transform, abilityTarget);
         StartCoroutine(Cooldown());
     }
     //if (Input.GetKeyDown(KeyCode.F)) loadout.EquipAbility(_newAbilityToTest);
     if (Input.GetKeyDown(KeyCode.Tab))
     {
         abilityTarget = transform;
     }
 }
コード例 #2
0
 private void CheckIfStartedMoving()
 {
     if (_isMoving == false)
     {
         StartRunning?.Invoke();
         Debug.Log("Started");
     }
     _isMoving = true;
 }
コード例 #3
0
 private void OnSprintRelease()
 {
     _isSprinting          = false;
     _movement.IsSprinting = false;
     if (_isMoving && _movement.IsGrounded == true)
     {
         StartRunning?.Invoke();
         //Debug.Log("Started Running");
     }
 }
コード例 #4
0
 private void CheckIfLanded()
 {
     if (controller.isGrounded && _isAirborne)
     {
         StartRunning?.Invoke();
         Debug.Log("Landed");
         _isAirborne = false;
         _isFalling  = false;
     }
 }
コード例 #5
0
 private void CheckIfStartedMoving()
 {
     if (_isMoving == false)
     {
         // our velocity says we're moving but we previously were not
         //this means we've started moving!
         StartRunning?.Invoke();
         Debug.Log("Started");
     }
     _isMoving = true;
 }
コード例 #6
0
 private void CheckIfStartedMoving()
 {
     if ((!_isRunning || _health.TakenDamage) && controller.isGrounded && !_isFalling && !_takingDamage)
     {
         StartRunning?.Invoke();
         _isRunning          = true;
         _isSprinting        = false;
         _health.TakenDamage = false;
         StartCoroutine(RunningSteps());
     }
 }
    // cancels sprint by setting back flag, and resumes running if still grounded
    private void CancelSprint()
    {
        if (IsSprinting)
        {
            IsSprinting = false;
        }

        if (Grounded() && IsRunning && _canSprint)
        {
            StartRunning?.Invoke();
        }
    }
コード例 #8
0
 private void CheckIfStartedMoving()
 {
     if (_isJumping || _beganFall || _isSprinting)
     {
         return;
     }
     if (!_isMoving)
     {
         StartRunning?.Invoke();
     }
     _isMoving = true;
 }
コード例 #9
0
 private void CheckIfStartedMoving()
 {
     if (_isMoving == false && _movement.IsGrounded == true)
     {
         if (_isSprinting)
         {
             StartSprinting?.Invoke();
             //Debug.Log("Started Sprinting");
         }
         else
         {
             StartRunning?.Invoke();
             //Debug.Log("Started Running");
         }
     }
     _isMoving = true;
 }
コード例 #10
0
            public void Start(string fileName)
            {
                #region Early Termination Checks
                if (string.IsNullOrWhiteSpace(fileName))
                {
                    return;
                }

                FileInfo temp;

                try
                {
                    temp = new FileInfo(fileName);
                }
                catch (Exception)
                {
                    MessageBox.Show(messageBoxText: "File Name is Not Valid", caption: "Malformed File Name", button: MessageBoxButton.OK, icon: MessageBoxImage.Error);
                    return;
                }

                if (!temp.Exists)
                {
                    MessageBox.Show(messageBoxText: "Provided File Name Could Not Be Located", caption: "File Not Found", button: MessageBoxButton.OK, icon: MessageBoxImage.Error);
                    return;
                }
                #endregion

                worker = new LogWorker(fileName);

                worker.MonitorStopped += delegate
                {
                    StopRunning?.Invoke(this, new EventArgs());
                };

                worker.OutputUpdate += (obj, args) =>
                {
                    Application.Current.Dispatcher.Invoke(new Action(() => output.Text = args.Output));
                };

                worker.RunWorkerAsync();

                StartRunning?.Invoke(this, new EventArgs());
            }
    // sets flag for player movement
    private void CheckIfStartedMoving()
    {
        // prevents overlap with jump animations in the animation controller
        if (!IsRunning && !IsJumping)
        {
            // this is set here as well because the sprint event depends on the player being in running state
            IsRunning = true;
            if (IsSprinting)
            {
                ApplySprint();
            }
            else if (_canBasic)
            {
                StartRunning?.Invoke();
            }
        }

        IsRunning = true;
    }
コード例 #12
0
 public void RecheckRunSprintIdle()
 {
     if (_movement.IsGrounded)
     {
         if (_isMoving)
         {
             if (_isSprinting)
             {
                 StartSprinting?.Invoke();
                 //Debug.Log("Land & Sprint");
             }
             else
             {
                 StartRunning?.Invoke();
                 //Debug.Log("Land & Run");
             }
         }
         else
         {
             Idle?.Invoke();
             //Debug.Log("Land & Idle");
         }
     }
 }
コード例 #13
0
    // Update is called once per frame
    void Update()
    {
        if (_isAlive)
        {
            //input to change push strength
            if (Input.GetKeyDown(KeyCode.E))
            {
                currentPushStrength += 1;
                PushBar.SetStrength(currentPushStrength);
                Debug.Log("Increased Push strength to " + currentPushStrength);
            }
            if (Input.GetKeyDown(KeyCode.Q))
            {
                currentPushStrength -= 1;
                PushBar.SetStrength(currentPushStrength);
                Debug.Log("Decreased Push strength to " + currentPushStrength);
            }
            //keep push strength within restraints
            if (currentPushStrength > 3)
            {
                currentPushStrength = 3;
            }
            if (currentPushStrength < 1)
            {
                currentPushStrength = 1;
            }

            //get player input for movement
            float horizontal = Input.GetAxisRaw("Horizontal");
            float vertical   = Input.GetAxisRaw("Vertical");

            //create direction of movement based on player input
            Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
            moveDirection = direction.magnitude;

            if (controller.isGrounded)
            {
                _isJumping = false;
            }

            //check to see if player is holding Left Shift to sprint, if player releases go back to normal run
            if (Input.GetKey(KeyCode.LeftShift))
            {
                _isSprinting = true;
            }
            else
            {
                _isSprinting = false;
            }
            if (Input.GetKeyDown(KeyCode.LeftShift) && direction.magnitude >= 0.1f)
            {
                CheckIfSprinting();
            }
            else if (Input.GetKeyUp(KeyCode.LeftShift) && direction.magnitude >= 0.1f)
            {
                StartRunning?.Invoke();
            }
            if (!_isSprinting && direction.magnitude >= 0.1)
            {
                CheckIfStartedMoving();
            }

            //if sprinting change the movement speed
            if (_isSprinting)
            {
                moveSpeed = sprintSpeed;
            }
            else
            {
                moveSpeed = speed;
            }

            if (controller.isGrounded)
            {
                velocityY = 0;
                //alow player to jump while grounded
                if (Input.GetButtonDown("Jump") && velocityY < 0.1f)
                {
                    velocityY = jumpSpeed;
                    StartJump?.Invoke();
                }
            }
            else if (!controller.isGrounded)
            {
                //apply gravity on player if they are not on the ground
                velocityY -= grav * Time.deltaTime;
                _isJumping = true;
            }

            if (direction.magnitude >= 0.1f)
            {
                if (!_isJumping)
                {
                    CheckIfStartedMoving();
                }


                //rotate player to face direction that they are moving in
                float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
                //smooth rotation
                float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
                transform.rotation = Quaternion.Euler(0f, angle, 0f);

                //move player in a direction if they are alive
                if (_isAlive)
                {
                    Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
                    controller.Move(moveDir.normalized * moveSpeed * Time.deltaTime);
                }
            }
            else
            {
                if (!_isJumping)
                {
                    CheckIfStoppedMoving();
                }
            }

            if (velocityY < -5f)
            {
                Falling?.Invoke();
            }

            //move in y direction if the player is alive
            if (_isAlive)
            {
                direction.y = velocityY;
                controller.Move(direction * Time.deltaTime);
            }
        }
    }
コード例 #14
0
    // Update is called once per frame
    void Update()
    {
        // Movement
        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical   = Input.GetAxisRaw("Vertical");

        Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;

        if (!_isAirborne && _isMoving)
        {
            if (Input.GetKeyDown(KeyCode.LeftShift) && !_isSprinting)
            {
                _isSprinting = true;
                StartSprinting?.Invoke();
            }
        }
        if (Input.GetKeyUp(KeyCode.LeftShift) && _isSprinting)
        {
            _isSprinting = false;
            if (!_isAirborne && _isMoving)
            {
                StartRunning?.Invoke();
            }
        }

        if (controller.isGrounded)
        {
            _vSpeed = 0f;
            if (Input.GetKeyDown("space"))
            {
                Jump?.Invoke();
                _vSpeed     = jumpSpeed;
                _isAirborne = true;
            }
        }
        else
        {
            if (!_playerCharacterAnimator.IsPlayingAny())
            {
                if (!_isFalling)
                {
                    StartFalling?.Invoke();
                    Debug.Log("Started Falling");
                    _isFalling = true;
                }
            }
        }

        if (direction.magnitude >= .1f || _vSpeed != 0)
        {
            CheckIfStartedMoving();
            float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
            float angle       = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
            transform.rotation = Quaternion.Euler(0f, angle, 0f);

            Vector3 moveDir = new Vector3();
            if (direction.magnitude >= .1f)
            {
                moveDir = (Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward).normalized;
            }

            if (!_isSprinting)
            {
                moveDir *= speed;
            }
            else
            {
                moveDir *= sprintSpeed;
            }

            _vSpeed  -= _gravity * Time.deltaTime;
            moveDir.y = _vSpeed;
            controller.Move(moveDir * Time.deltaTime);

            CheckIfLanded();
        }
        else
        {
            CheckIfStoppedMoving();
        }
    }