private void Update() { if (PauseManager.Paused) { return; } if (DoggoController.win) { _renderer.enabled = false; return; } var move = Mathf.Abs(Input.GetAxis("Horizontal")) > 0.5f; if (!_playerController.IsDead()) { _dir = _rb.velocity.x < 0f; if (!move || _shooting) { _dir = !_throw.dir; } if (_playerController.OnWall()) { _dir = _advCol.CheckCollision(AdvPlayerCollider.Side.Right); } } _renderer.flipX = _dir; _anim.SetBool($"Dead", _health.CheckIfDead()); _anim.SetBool($"Shooting", _shooting); _anim.SetBool($"Grounded", _advCol.IsGrounded()); _anim.SetBool($"OnWall", _playerController.OnWall()); _anim.SetBool($"Moving", move); _anim.SetBool($"OnLadder", _playerController.OnLadder()); var climb = Math.Abs(Input.GetAxis("Vertical")) > 0.5f; climb = _playerController.OnLadder() && climb; _anim.SetBool($"Climbing", climb); }
private void Update() { if (PauseManager.Paused) { return; } if (DoggoController.win) { return; } myPreviousState = myCurrentState; SoundLoopLogic(); if (_dead) { return; } //Movement var ground = _advCol.CheckCollision(AdvPlayerCollider.Side.Down); if (IsGround(ground)) { var norm = DirectCast(ground).normal; var dir = (Quaternion.Euler(0f, 0f, -90f) * norm).normalized; _rb.velocity = Input.GetAxis("Horizontal") * speed * dir; } else { _rb.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, _rb.velocity.y); } if (CollisionLeft()) { _rb.velocity = new Vector2(Mathf.Max(0f, _rb.velocity.x), _rb.velocity.y); } if (CollisionRight()) { _rb.velocity = new Vector2(Mathf.Min(0f, _rb.velocity.x), _rb.velocity.y); } //Wall rebound; if (_reboundTm > 0 && !_onLadder) { _reboundTm -= Time.deltaTime; _rb.velocity = new Vector2(_reboundDir * speed * wallJumpRebound, _rb.velocity.y); } if (_nearLadder && Mathf.Abs(Input.GetAxis("Vertical")) > 0f) { _onLadder = true; } //Dashing if (_dashTm > 0) { _dashTm -= Time.deltaTime; _rb.velocity = new Vector2(_dashDir * dashForce, _rb.velocity.y); } if (Input.GetButtonDown($"Dash") && _canDash) { onDash?.Invoke(); _dashTm = dashTime; _dashDir = Mathf.Sign(Input.GetAxis("Horizontal")); _canDash = false; } //Wall sliding _rb.gravityScale = OnWall() ? wallGravity : defaultGravity; //Ladder climbing if (_onLadder) { _reboundTm = 0f; _rb.gravityScale = 0f; _rb.velocity = new Vector2(_rb.velocity.x, Input.GetAxis("Vertical") * climbingSpeed); _canDoubleJump = true; return; } //Terminal velocity check if (_rb.velocity.y < maxFallingSpeed * -1f) { _rb.velocity = new Vector2(_rb.velocity.x, maxFallingSpeed * -1f); } if (OnWall()) { _canDoubleJump = false; _canDash = true; if (_rb.velocity.y < maxSlidingSpeed * -1f) { _rb.velocity = new Vector2(_rb.velocity.x, maxSlidingSpeed * -1f); } } if (_advCol.IsGrounded()) { _rb.gravityScale = 0f; _canDoubleJump = true; _canDash = true; } //Jumps if (Input.GetButtonDown("Jump")) { myCurrentState = PlayerState.NoneOfTheAbove; //Ground Jump if (_advCol.IsGrounded()) { onJump?.Invoke(); _rb.AddForce(Vector2.up * jumpForce); _sounds.PlayJumping(); } else if (OnWall()) { //Wall Jump onWallJump?.Invoke(); _reboundDir = _advCol.CheckCollision(AdvPlayerCollider.Side.Right) ? -1f : 1f; _rb.velocity = new Vector2(_rb.velocity.x, 0f); _rb.AddForce(Vector2.up * wallJumpForce); _reboundTm = reboundTime; _sounds.PlayJumping(); _sounds.StopSounds(); } else if (_canDoubleJump) { //Double Jump onDoubleJump?.Invoke(); _rb.velocity = new Vector2(_rb.velocity.x, 0f); _rb.AddForce(Vector2.up * doubleJumpForce); _canDoubleJump = false; _sounds.PlayDoubleJumping(); } } if (myPreviousState != myCurrentState) { _sounds.StopSounds(); } }