private void FixedUpdate() { transform.Translate(new Vector3(0, (currentSpeed < 0 ? currentSpeed * fallingMultiplier : currentSpeed) * Time.fixedDeltaTime, 0)); if (!isJumping) { return; } if (transform.position.y < losePosition) { onJump.Invoke(false); loseEvent.Invoke(); return; } for (int i = 0; i < columns.columns.Count; i++) { Transform column = columns.columns[i]; if (column.position.y <= transform.position.y && column.position.y + positionOddY >= transform.position.y) { if (column.position.x - positionOddX <= transform.position.x && column.position.x + positionOddX >= transform.position.x) { currentSpeed = 0; isRecovering = true; isJumping = false; landingPosition = transform.position; nextColumnIndex = i; onJump.Invoke(false); onLand.Invoke(); currentColumn = column; currentColumnIndex = i; nextColumnIndex = nextColumnIndex + 1 >= columns.columns.Count ? 0 : nextColumnIndex + 1; return; } } } if (columns.columns[nextColumnIndex].position.x - transform.position.x >= 0) { if (transform.position.y < columns.columns[nextColumnIndex].position.y) { if (columns.columns[nextColumnIndex].position.x - transform.position.x <= faceplantDistance) { onJump.Invoke(false); } } } else { nextColumnIndex = nextColumnIndex + 1 >= columns.columns.Count ? 0 : nextColumnIndex + 1; print("current " + currentColumnIndex + ", next" + nextColumnIndex); } currentSpeed -= fallSpeed * Time.fixedDeltaTime; }
private void Update() { if (Input.GetMouseButtonUp(0) || Input.GetKeyUp(KeyCode.Space)) { OnJump?.Invoke(); } }
void Update() { if (Input.GetKeyDown("space")) { OnJump?.Invoke(); } }
public override void OnJumpButton() { ratBrain.CurrentAnimationState.OnJumpButton(); //should maybe pull up to brain OnJump?.Invoke(); ratBrain.SetState(ratBrain.AvailableStates[typeof(AirBorne)]); }
private void GetJumpInput() { if (Input.GetAxisRaw("Jump") > 0) { 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(); } }
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); }
public void Jump() { if (CanJump()) { return; } speed.y = jump_impulsion_speed; _physicsHandler.VerticalSpeed = speed.y; Jump_count++; isJumping = true; OnJump?.Invoke(); }
// 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; }
private void Update() { Horizontal = Input.GetAxis("Horizontal"); if (Input.GetButtonDown("Jump")) { OnJump?.Invoke(); } if (Input.GetButtonDown("Switch")) { OnSwitch?.Invoke(); } }
public void Jump() { if (!IsOnTask && !IsOnAir && LastAction != Action.JUMP) { LastAction = Action.JUMP; IsJumping = true; OnJump?.Invoke(this, null); } if (!IsOnAir || IsFalling) { IsJumping = false; } }
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; }
//Launches the player when pressing the jump button void Jump() { //If the player presses X while not pressing LeftTrigger and can jump //if (Input.GetButtonDown("Cross") && !Input.GetButton("LeftTrigger") && canJump) if (InputManager.Instance.GetKeyDown(ControllerInput.Jump) && !GetComponentInChildren <ElementEffects>().isCasting) { if (CanJump) { anim.SetTriggerAnimParam("Jump"); //Set the y velocity to the specified jump height moveDirection.y = JumpHeight; //And set canJump to false CanJump = false; source.clip = JumpSFX; source.Play(); if (onJump != null) { onJump.Invoke(); } if (GetComponent <UseSkill>().GetElement(typeof(WindElement)).IsElementUnlocked) { canDoubleJump = true; } } else if (canDoubleJump && GetComponent <UseSkill>().GetElement(typeof(WindElement)).IsElementUnlocked) { JumpVFX.GetComponent <ParticleSystem>().Play(); moveDirection.y = 0; moveDirection.y += JumpHeight; CanJump = false; canDoubleJump = false; source.clip = DoubleJumpSFX; source.Play(); if (onDoubleJump != null) { onDoubleJump.Invoke(); } } } }
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); }