public override void OnJumpButton() { ratBrain.CurrentAnimationState.OnJumpButton(); //should maybe pull up to brain OnJump?.Invoke(); ratBrain.SetState(ratBrain.AvailableStates[typeof(AirBorne)]); }
void Jump() { CurrentLedge = null; OnJump.SafeInvoke(); PhysicsState.SetVerticalVelocity(_jumpPower[MaxJumpCount - JumpCount]); CmdJump(); }
void Update() { if (Input.GetKeyDown("space")) { OnJump?.Invoke(); } }
private void GetJumpInput() { if (Input.GetAxisRaw("Jump") > 0) { OnJump?.Invoke(); } }
private void Update() { if (Input.GetMouseButtonUp(0) || Input.GetKeyUp(KeyCode.Space)) { OnJump?.Invoke(); } }
private void Update() { bool jumpPressed = Input.GetButtonDown("Jump"); if (!gameManager.IsGameOver) { // Game is not yet over if (jumpPressed) { if (!playerReady) { OnPlayerReady?.Invoke(); playerReady = true; } OnJump?.Invoke(); } } else { // Game is over if (jumpPressed) { if (!isRestarting) { RestartGameClick(); } } } }
private void Jump(InputAction.CallbackContext context) { if (OnGround()) { _rigidbody.AddForce(transform.up * _jumpForce, ForceMode2D.Impulse); OnJump?.Invoke(); } }
/// <summary> /// Makes the player jump. /// </summary> protected virtual void Jump() { // Set 'isJumping' to true so the player tells everything we're jumping. isJumping = true; // The player should no longer jump. shouldJump = false; // Reset the current air time. currentAirTime = 0; // If the player is crouching when trying to jump, check if the player can jump while crouched. // If the player isn't crouching, just jump. if (isCrouching) { // If crouch jumping is enabled, jump. Else do nothing. if (crouchJumping) { moveDirection.y = realJumpHeight; } } else { moveDirection.y = realJumpHeight; } // Increment the air jumps. currentJumps++; if (currentJumps > 0 && allowAirJumpDirectionChange) { // Get the move direction from the movement input X and Y (on the Z axis). moveDirection = new Vector3(movementInput.x, moveDirection.y, movementInput.y); // If movement input Y is above 0, we're moving forward, so apply forward move speed. // Else if below 0, we're moving backwards, so apply backwards move speed. if (movementInput.y > 0) { moveDirection.z *= moveSpeed.ForwardSpeed; } else { moveDirection.z *= moveSpeed.BackwardsSpeed; } // Apply the sideways movement speed to the X movement. moveDirection.x *= moveSpeed.SidewaysSpeed; // Update the grounded velocity to the current move direction. groundVelocity = moveDirection; } // Invoke the OnPlayerJump event. #if NET_4_6 || (UNITY_2018_3_OR_NEWER && !NET_LEGACY) OnJump?.Invoke(jumpHeight); #else if (OnJump != null) { OnJump.Invoke(jumpHeight); } #endif }
private void CheckJumping() { if (!_lastFrameJumpState && _jumper.Jumping) { OnJump?.Invoke(); } _lastFrameJumpState = _jumper.Jumping; }
protected override void Jumping() { MoveCommond = new Vector2(Mathf.Round(MoveCommond.x), Mathf.Round(MoveCommond.y)); direction = MoveCommond; if (groundDetector.OnGround) { base.Jumping(); OnJump?.Invoke(jumpHeight); } }
private void Update() { Horizontal = Input.GetAxis("Horizontal"); Vertical = Input.GetAxis("Vertical"); IsRunning = Input.GetButton("Fire1"); if (Input.GetButtonDown("Jump")) { OnJump?.Invoke(); } }
public void Jump() { if (CanJump()) { return; } speed.y = jump_impulsion_speed; _physicsHandler.VerticalSpeed = speed.y; Jump_count++; isJumping = true; OnJump?.Invoke(); }
private void Update() { if (Input.GetKeyDown(KeyCode.K)) { OnInteractionPressed?.Invoke(); } if (!IsEnabled) { return; } HorizontalMovement = Input.GetAxis("Horizontal"); VerticalMovement = Input.GetAxis("Vertical"); if (Input.GetKeyDown(KeyCode.J)) { OnJump?.Invoke(); } if (Input.GetKey(KeyCode.S)) { OnDownKey?.Invoke(); } if (Input.GetKeyUp(KeyCode.S)) { OnDownKeyReleased?.Invoke(); } if (Input.GetKey(KeyCode.K)) { OnInteraction?.Invoke(); } if (Input.GetKeyUp(KeyCode.K)) { OnInteractionReleased?.Invoke(); } if (Input.GetKeyDown(KeyCode.R)) { AppData.GameManager.RestartLevel(); } if (Input.GetKeyDown(KeyCode.Escape)) { if (SceneManager.GetActiveScene().buildIndex != (int)SceneName.MainMenu) { AppData.SceneLoader.LoadScene(SceneName.MainMenu); } } }
public void JumpFrames(long frameDelta) { if (VideoTexture == null || frameDelta == 0) { return; } var nextFrame = CurrentFrame + frameDelta; OnJump?.Invoke(); SeekFrame(nextFrame); }
// Update is called once per frame new void FixedUpdate() { if (Disable) // dirty hack, dont do it like this { HMomentum = 0f; base.FixedUpdate(); return; } cyoteTime--; if (Grounded) { if (Mathf.Abs(HMomentum) < 1f && InputToken.AbsHor == 0f) { HMomentum = 0f; } else { HMomentum = HMomentum * (1f - groundControl) + InputToken.Horizontal * speed * groundControl; } airJump = airJumps; UpdateFacing(); cyoteTime = 5; } else { HMomentum = HMomentum * (1f - airControl) + InputToken.Horizontal * speed * airControl; } if (cyoteTime >= 0 && InputToken.Jump) { VMomentum = jumpForce; InputToken.ClearJump(); OnJump?.Invoke(); } else if (airJump > 0 && InputToken.Jump && (VMomentum <= 0f || VMomentum > 1f)) { // the snippet works together with the input buffer to help you nail the air jump at the top of your arc VMomentum = jumpForce * .8f; InputToken.ClearJump(); OnJump?.Invoke(); HMomentum = InputToken.Horizontal * speed; airJump--; UpdateFacing(); } base.FixedUpdate(); Gravity = InputToken.HoldJump && VMomentum > 0f ? 16f : 30f; if (Grounded == false && VMomentum > 0f & !InputToken.HoldJump) { VMomentum *= .8f; } }
protected override void Jumping(Vector3 direction) { var vel = rigidBody.velocity; // Concluded from S = Vi * t + 1/2 * a * t^2 and t = (Vf - Vi)/a vel.y = Mathf.Sqrt(19.62f * jumpHeight * rigidBody.gravityScale); rigidBody.velocity = vel; if (OnJump != null) { OnJump.Invoke(); } }
internal void Jump() { if (OnJump == null) { return; } if (!AllowMovement) { return; } OnJump.Invoke(); }
public void Jump() { if (rigid) { rigid.velocity = Vector2.zero; rigid.AddForce(new Vector2(0, upForce)); } if (OnJump != null) { OnJump.Invoke(); } }
private void UpdateJump() { _jumpGravity = -(2 * maxJumpHeight) / Mathf.Pow(timeToJumpHeight, 2); _fallGravity = -(2 * maxJumpHeight) / Mathf.Pow(timeToFallJump, 2); _normalGravity = -(2 * maxJumpHeight) / Mathf.Pow(timeToFallnormal, 2); _jumpVelocity = Mathf.Abs(_jumpGravity) * timeToJumpHeight; if (_controller2D.isGrounded) { _jumpTime = timeToJumpHeight; _velocity.y = 0; if (_jumpInput && _canJump) { _velocity.y = _jumpVelocity; _jumpTime = 0; _canJump = false; _hasJump = true; _lastJump = Time.time; OnJump?.Invoke(); } else { _hasJump = false; } } if (!_jumpInput && Time.time >= _lastJump + jumpCooldown) { _canJump = true; } if (!_jumpInput && _jumpTime > minJumpTime) { _jumpTime = timeToJumpHeight; } if (_hasJump) { _gravity = _jumpTime >= timeToJumpHeight ? _fallGravity : _jumpGravity; } else { _gravity = _normalGravity; } _jumpTime += Time.deltaTime; _velocity.y += _gravity * Time.deltaTime; }
public void Jump() { if (!IsOnTask && !IsOnAir && LastAction != Action.JUMP) { LastAction = Action.JUMP; IsJumping = true; OnJump?.Invoke(this, null); } if (!IsOnAir || IsFalling) { IsJumping = false; } }
private void Update() { Horizontal = Input.GetAxis("Horizontal"); if (Input.GetButtonDown("Jump")) { OnJump?.Invoke(); } if (Input.GetButtonDown("Switch")) { OnSwitch?.Invoke(); } }
void UnconditionalJump() { OnJump?.Invoke(); rb.velocity = new Vector3( rb.velocity.x, jumpForce * Time.fixedDeltaTime * Mathf.Pow( speed / startingTargetSpeed, speedRatioToJumpForceExponent ), rb.velocity.z ); midAir = true; jumpedThisFrame = true; framesSinceLastJump = 0; }
private void Jump() { grounded = false; if (jetpack.enabled) { jetpack.Launch(jumpVelocity, maxVelocityVector); } notifiedJump = false; OnJump.Invoke(); KillVelocity(); dragging = false; trajectoryPrediction.RemoveIndicators(); StartCoroutine(RemoveGravityTemporarily()); rigidbody2d.AddForce(jumpVelocity, ForceMode2D.Impulse); }
/// <summary> /// Removes any current y-direction movement on the player, applies a one time impulse force to the player upwards, /// then waits jumpCooldown seconds to be ready again. /// </summary> void Jump() { OnJump?.Invoke(); AudioManager.instance.PlayOnGameObject(AudioName.PlayerJump, ID, this); timeSpentJumping = 0.0f; underMinJumpTime = true; grounded.isGrounded = false; Vector3 jumpVector = -Physics.gravity.normalized * jumpForce; thisRigidbody.AddForce(jumpVector, ForceMode.Impulse); StartCoroutine(PrintMaxHeight(transform.position)); jumpState = JumpState.Jumping; }
void Jump() { if (isJumping) { return; } isJumping = true; isGrounded = false; ResetGround(); velocity.y = jumpForce; OnJump?.Invoke(); }
void Jump() { if (isJumping) { return; } isJumping = true; isGrounded = false; ResetGround(); velocity.y = jumpForce; //cameraTargetProbe.damping.y = dampingOnAir; OnJump?.Invoke(); }
void FixedUpdate() { bool isOnGround = Physics2DUtility.IsOnGround(transform.position, myCollider); bool isAffectedByGravity = myRigidbody.gravityScale > 0; // Jump take-off if (startJump && (isOnGround || !isAffectedByGravity) && !isOnCooldown) { Vector2 jumpDirection, finalJumpForce; if (isAffectedByGravity) { jumpDirection = new Vector2(direction.x, 1); finalJumpForce = jumpForce; } else { jumpDirection = direction; if (jumpDirection == Vector2.zero) { jumpDirection = Vector2.up; } finalJumpForce = new Vector2(jumpForce.y, jumpForce.y); } myRigidbody.AddForce(jumpDirection * finalJumpForce, ForceMode2D.Impulse); OnJump?.Invoke(); isOnCooldown = true; Invoke(nameof(EnableJump), cooldownTime); } // Jump maneuvers if (!isOnGround && isAffectedByGravity) { myRigidbody.AddForce(Vector2.right * direction.x * lateralForce); if (extendJump && myRigidbody.velocity.y > 0) { myRigidbody.AddForce(Vector2.up * extendForce); } } startJump = false; extendJump = false; }
private void Update() { float moveInput = Input.GetAxis("Horizontal"); if (!moveInput.Equals(0)) { OnHorizontalAxis?.Invoke(moveInput); } else { OnHorizontalAxisZero?.Invoke(); } if (Input.GetKeyDown(KeyCode.Space)) { OnJump?.Invoke(); } }
private void OnTouchHandle(TouchHandler touchHandler) { OnTryJump?.Invoke(this); if (CanMove == false) { return; } if (lastInput == touchHandler) { return; } if (jumpsLeft == 0) { bufferedTouch = touchHandler; bufferedTouchTime = Time.time; return; } if (lastJumpTime + minJumpInterval > Time.time) { bufferedTouch = touchHandler; bufferedTouchTime = Time.time; return; } bool rushing = OnStopRushCharge(touchHandler); lastJumpTime = Time.time; lastInput = touchHandler; float rushScale = rushing ? rushForceMultiplier : 1; Vector2 velocity = new Vector2( touchHandler.Direction * sidewardVelocity * timeScaller.TimeScale * rushScale, upwardVelocity * timeScaller.TimeScale * rushScale); rigidbody2D.velocity = velocity; if (jumpsLeft > 0) { jumpsLeft -= 1; } playerVisuals.PlayJumpParticles(-velocity.normalized); MusicPlayer.Instance.PlayJump(); OnJump?.Invoke(this); }
// Update is called once per frame void Update() { if (Input.GetKey(KeyCode.A)) { currentSpeed = Mathf.Lerp(currentSpeed, -speed, Time.deltaTime * accellerationTime); } else if (Input.GetKey(KeyCode.D)) { currentSpeed = Mathf.Lerp(currentSpeed, speed, Time.deltaTime * accellerationTime); } else { currentSpeed = Mathf.Lerp(currentSpeed, 0, Time.deltaTime * accellerationTime * 3); } Rigidbody2D.velocity = new Vector2(currentSpeed, Rigidbody2D.velocity.y); if (Input.GetKeyDown(KeyCode.Space)) { OnJump?.Invoke(); } }