protected virtual void OnJump() { if (OnJumpEvent != null) { OnJumpEvent.Invoke(); } }
// Update is called once per frame void Update() { if (Input.GetButtonDown("Jump")) { OnJump.Invoke(); } OnDirection.Invoke(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")); }
public void StartJumpWithOptions(bool ignoreMaximumJumps, float angle, float force) { if ((!ignoreMaximumJumps && _currentJumps >= maxJumps) || _jumping) { return; } _jumping = true; Grounded = false; _jumpTime = Time.time; _currentJumps++; var velocity = _myRigidBody2D.velocity; velocity.y = velocity.y < 0 ? 0 : velocity.y; _myRigidBody2D.velocity = velocity; _jumpDirection = new Vector2(0f, force); _jumpDirection = Quaternion.Euler(0, 0, angle) * _jumpDirection; _myRigidBody2D.AddForce(_jumpDirection * 5); OnJumpEvent?.Invoke(); }
private void HandleJump() { if (Input.GetButtonDown("Jump") && !state.isReeling) { //standard jump if (_mover.IsGrounded) { //formula derived from vf^2 = vi^2 + 2ad _velocity.y = Mathf.Sqrt(2f * maxJumpHeight * -gravity); OnJumpEvent?.Invoke(); } //wall jump else if ((_mover.IsRightOfWall || _mover.IsLeftOfWall) && wallJumpAcquired) { state.ResetAbilityUsage(); int sign = (_mover.IsRightOfWall) ? -1 : 1; float wallJumpX = slideJumpLength * sign; float wallJumpY = Mathf.Sqrt(2f * slideJumpHeight * -gravity); EnterReelingState(wallJumpDuration, new Vector2(wallJumpX, wallJumpY), false); OnWallJumpEvent?.Invoke(); } //double jump else if (!state.hasDoubleJumped && doubleJumpAcquired) { state.hasDoubleJumped = true; _velocity.y = Mathf.Sqrt(2f * maxJumpHeight * -gravity); OnDoubleJumpEvent?.Invoke(); } } //if jump is cancelled, set player velocity to be equal to initial velocity as defined by minJumpHeight. if (Input.GetButtonUp("Jump") && _velocity.y > Mathf.Sqrt(2f * minJumpHeight * -gravity)) { _velocity.y = Mathf.Sqrt(2f * minJumpHeight * -gravity); } }
public void OnJump(object sender, EventArgs e) { OnJumpEvent?.Invoke(this, EventArgs.Empty); }
public void Move(float move, bool crouch, bool jump) { bool JumpUnder = false; // ���� ���� �ִ��� �Ǻ�, �ɱ� ���� ���� �ʿ伺�� ���� if (!crouch) { if (Physics2D.OverlapCircle(m_CeilingCheck.position, k_CeilingRadius, m_WhatIsGround)) { crouch = true; } } if (m_Grounded) { if (m_JumpDisableCollider != null) { m_JumpDisableCollider.enabled = true; } // �ɱ� ���¶�� �Է��� ���� ��� if (crouch) { Collider2D promp = Physics2D.OverlapCircle(m_GroundCheck.position, k_GroundedRadius, m_WhatIsPlatform); if (promp && jump) { effector = promp.GetComponent <PlatformEffector2D>(); JumpUnder = true; StartCoroutine(VerticalJump()); } if (!m_wasCrouching)//ij���� ���� ���� ���·� �ٲ�� { m_wasCrouching = true; // �ɱ� ������ ���� �ݸ��� ���� Axis.position = new Vector3(Axis.position.x, Axis.position.y - 0.82f, Axis.position.z); OnCrouchEventTrue.Invoke();//�ɱ� ���·� �ٲٸ鼭 �̺�Ʈ ����. } if (m_CrouchDisableCollider != null) { m_CrouchDisableCollider.enabled = false; } // �ӵ� ���� move *= m_CrouchSpeed; } else { if (m_wasCrouching) { m_wasCrouching = false; // �ɱ� ���°� �ƴ� ��� �ݸ��� ���� Axis.position = new Vector3(Axis.position.x, Axis.position.y + 0.82f, Axis.position.z); if (m_CrouchDisableCollider != null) { m_CrouchDisableCollider.enabled = true; } OnCrouchEventFalse.Invoke();//���̵� ���·� �ٲٸ鼭 �κ�Ʈ ����. } } } // ���ϴ� �������� �ӷ��� �߰��� �̵� Vector3 targetVelocity = new Vector2(move * 10f, m_Rigidbody2D.velocity.y); // �������� �ڿ������� m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing); // ���� ���� �پ��ְ� ���� �Է��� ���� ��� if (m_Grounded && jump && !JumpUnder && !isJumpCooldown) { // ���� ���� �� m_Grounded = false; //���� �پ��ִ����� �ǽð����� Ȯ�� m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce)); StartCoroutine(CooldownJump()); OnJumpEvent.Invoke(); if (m_JumpDisableCollider != null) { m_JumpDisableCollider.enabled = false; } if (m_CrouchDisableCollider != null) { m_CrouchDisableCollider.enabled = true; } } }