private void HandleBoomJump() { Movement(); if (canJump) { canJump = !canJump; OnPlayerJump?.Invoke(canJump); ExplosionAnimator.SetBool("isTriggered", true); // Trigger Explosion Sound Here BoomJumpSource.Play(); RB.velocity = new Vector2(RB.velocity.x, 0); RB.AddForce(Vector2.up * explosiveForce, ForceMode2D.Impulse); // Damage player DamagePlayer(explosiveDamage); } Collider2D[] cols = Physics2D.OverlapCapsuleAll(ExplosionCollider.bounds.center, ExplosionCollider.size, CapsuleDirection2D.Horizontal, 0); foreach (Collider2D col in cols) { if (col.GetComponent <TNT>() != null) { TNT tnt = col.GetComponent <TNT>(); tnt.Detonate(true); } } if (PlayerAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime > 1) { if (!grounded) { SetState(PlayerStates.IN_AIR); } } }
/// <summary> /// Makes the player jumps a second time while in the air. /// </summary> void SecondJump() { playerRb.AddForce(Vector3.up * doubleJumpForce, ForceMode.Impulse); hasDoubleJumped = true; playerAnim.SetTrigger("Double_Jump_trig"); playerAudio.PlayOneShot(jumpSound, jumpVolume); OnPlayerJump?.Invoke(); }
/// <summary> /// Makes the player to jump upwards. /// </summary> void FirstJump() { playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse); isGrounded = false; playerAnim.SetTrigger("Jump_trig"); dirtParticle.Stop(); playerAudio.PlayOneShot(jumpSound, jumpVolume); OnPlayerJump?.Invoke(); }
private void GetJumpPromt() { if (isGrounded && Input.GetButtonDown(JUMP)) { _anim.SetTrigger("Jump"); OnPlayerJump?.Invoke(); isJumping = true; jumpTimeCounter = GameManager.Instance.playerMaxJumpDuration; } }
private void Update() { IsGrounded = Physics2D.OverlapBox(GroundCheck.position, GroundCheckBox, 0f, GroundLayer); if (IsGrounded) { _timeAfterGrounded = CoyoteTime; } else { _timeAfterGrounded -= Time.deltaTime; } _timerNoGroundRegister -= Time.deltaTime; _timeJumpButtonRegistered -= Time.deltaTime; /* Just for absolutely non-abuse system */ if (IsGrounded == true && InMidair == true && _timerNoGroundRegister <= 0f) { InMidair = false; } if (Input.GetButtonDown("Jump")) { _timeJumpButtonRegistered = JumpPreregisterTime; } if (_timeJumpButtonRegistered > 0f && Input.GetButton("Jump") && (IsGrounded == true || _timeAfterGrounded > 0f) && InMidair == false) { OnPlayerJump?.Invoke(); InMidair = true; _timerNoGroundRegister = NoCheckingGroundTime; _jumpHelded = true; } if (Input.GetButtonUp("Jump") && _jumpHelded) { _jumpHelded = false; } /* Player movement */ _moveInput = Input.GetAxisRaw("Horizontal"); //Вынес в Fixed, потому что так прпавильно }
private void HandleBombJumpCoolDownTimer() { if (!canJump) { if (currentState != PlayerStates.SPIKE_DEAD || currentState != PlayerStates.BOOM_DEAD) { if (bombCoolDownTimer > 0) { bombCoolDownTimer -= Time.deltaTime; } else { ExplosionAnimator.SetBool("isTriggered", false); canJump = true; bombCoolDownTimer = bombCoolDownTime; OnPlayerJump?.Invoke(canJump); } } } }
private void Update() { if (Input.GetKey(KeyCode.A)) { OnPlayerHorizontal?.Invoke(-1); isMovingHor = true; } else if (Input.GetKey(KeyCode.D)) { OnPlayerHorizontal?.Invoke(1); isMovingHor = true; } //DUDAS SOBRE OPTIMIZACIÓN else if (isMovingHor && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D)) { OnPlayerHorizontal?.Invoke(0); isMovingHor = false; } if (Input.GetKey(KeyCode.S)) { OnPlayerVertical?.Invoke(-1); isMovingVer = true; } else if (Input.GetKey(KeyCode.W)) { OnPlayerVertical?.Invoke(1); isMovingVer = true; } else if (isMovingVer && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.W)) { OnPlayerVertical?.Invoke(0); isMovingVer = false; } if (Input.GetMouseButtonDown(0)) { OnPlayerAttack?.Invoke(); } if (Input.GetKeyDown(KeyCode.E)) { OnPlayerFire?.Invoke(); } if (Input.GetMouseButton(1)) { OnPlayerBlock?.Invoke(); } else if (Input.GetMouseButtonUp(1)) { OnPlayerStopBlocking?.Invoke(); } if (Input.GetKeyDown(KeyCode.Space)) { OnPlayerJump?.Invoke(); } if (Input.GetKeyDown(KeyCode.Escape)) { OnEscape?.Invoke(); } }