private void HandleMovement() { if (IsGrounded) { _velocity.y = 0; _numJumps = 0; } if (CanMove) { float horizontalMovement = CharacterYoke.Movement.x; if ((_numJumps < MaxJumps || IsGrounded) && !CharacterYoke.Jump) { _jumpAvailable = _config.JumpHeight; _canJump = true; } // we can only jump whilst grounded if (_canJump && CharacterYoke.Jump && _jumpAvailable > 0.0f) { if (CharacterYoke.GetButtonDown(InputAction.Jump)) { _jumpStartTime = Time.time; _numJumps++; } float jumpThisFrame = _config.GetJumpSpeed(Time.time - _jumpStartTime) * Time.deltaTime; _jumpAvailable -= jumpThisFrame; _velocity.y = Mathf.Sqrt(2f * jumpThisFrame * -_config.Gravity); } else { // apply gravity before moving _velocity.y += _config.Gravity * Time.deltaTime; } if (CharacterYoke.GetButtonUp(InputAction.Jump)) { _canJump = false; } _velocity.x = horizontalMovement * _config.RunSpeed * RunSpeedModifier; // if holding down bump up our movement amount and turn off one way platform detection for a frame. // this lets us jump down through one way platforms if (IsGrounded && CharacterYoke.GetButtonDown(InputAction.Drop)) { _velocity.y *= 3f; IgnoreOneWayPlatformsThisFrame = true; } } else { _velocity.x = 0.0f; } _velocity = MoveBy(_velocity, _velocity * Time.deltaTime); }
private IEnumerator RangedAttack() { IsRangedAttacking = true; Events.OnRangedAttackBegin.InvokeSafe(); Projectile projectile = _rangedAttackPool.GetInstance <Projectile>(null); Vector3 position = _collider.bounds.center; Vector3 direction = Vector3.zero; float vertical = CharacterYoke.GetAxis(InputAction.MoveVertical); if (vertical != 0.0f) { if (vertical < 0.0f) { //Trying to hit down //If we're on the ground, we can't slash down if (IsGrounded) { yield break; } position.y -= _collider.bounds.extents.y; direction = Vector3.down; } else { position.y += _collider.bounds.extents.y; direction = Vector3.up; } } else { if (FacingDirection == Facing.Right) { direction = Vector3.right; position.x += _collider.bounds.extents.x; } else { direction = Vector3.left; position.x -= _collider.bounds.extents.x; } } projectile.transform.position = position; projectile.Setup(this, Config.BaseRangedDamage, direction * Config.ProjectileSpeed, _rangedAttackPool); projectile.OnHit += OnRangedHit; projectile.OnReturnToPool += OnProjectileReturnToPool; yield return(new WaitForSeconds(Config.RangedAttackSpeed)); IsRangedAttacking = false; Events.OnRangedAttackEnd.InvokeSafe(); }
private void HandleAttacking() { if (CanMeleeAttack() && CharacterYoke.GetButtonDown(InputAction.MeleeAttack)) { StartCoroutine(MeleeAttack()); } if (CanRangedAttack() && CharacterYoke.GetButtonDown(InputAction.RangedAttack)) { StartCoroutine(RangedAttack()); _lastRangedAttackTime = Time.time; } if (CanDashAttack() && CharacterYoke.GetButtonDown(InputAction.DashAttack)) { StartCoroutine(DashAttack()); } }
protected IEnumerator MeleeAttack() { _meleeAttack.transform.localScale = Vector3.zero; Vector3 position = _collider.bounds.center; float target = 1.0f; float vertical = CharacterYoke.GetAxis(InputAction.MoveVertical); if (vertical != 0.0f) { if (vertical < 0.0f) { //Trying to hit down //If we're on the ground, we can't slash down if (IsGrounded) { yield break; } _meleeAttack.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 90.0f); position.y -= _collider.bounds.extents.y; } else { _meleeAttack.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, -90.0f); position.y += _collider.bounds.extents.y; } } else { _meleeAttack.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 0.0f); if (FacingDirection == Facing.Right) { target = -1.0f; position.x += _collider.bounds.extents.x; } else { target = 1.0f; position.x -= _collider.bounds.extents.x; } } IsMeleeAttacking = true; Events.OnMeleeAttackBegin.InvokeSafe(); _meleeAttack.transform.position = position; _meleeAttack.SetActive(true); float duration = 0.0f; float t = 0.0f; while (t <= 1.0f) { _meleeAttack.transform.localScale = new Vector3(Mathf.Lerp(0.0f, target, t), 1.0f, 1.0f); duration += Time.deltaTime; t = duration / Config.MeleeAttackSpeed; yield return(null); } _meleeAttack.SetActive(false); IsMeleeAttacking = false; _meleeAttackEndTime = Time.time; Events.OnMeleeAttackEnd.InvokeSafe(); }