예제 #1
0
        public override void OnJumpButton()
        {
            ratBrain.CurrentAnimationState.OnJumpButton();                    //should maybe pull up to brain

            OnJump?.Invoke();
            ratBrain.SetState(ratBrain.AvailableStates[typeof(AirBorne)]);
        }
예제 #2
0
 void Jump()
 {
     CurrentLedge = null;
     OnJump.SafeInvoke();
     PhysicsState.SetVerticalVelocity(_jumpPower[MaxJumpCount - JumpCount]);
     CmdJump();
 }
예제 #3
0
 void Update()
 {
     if (Input.GetKeyDown("space"))
     {
         OnJump?.Invoke();
     }
 }
예제 #4
0
 private void GetJumpInput()
 {
     if (Input.GetAxisRaw("Jump") > 0)
     {
         OnJump?.Invoke();
     }
 }
예제 #5
0
 private void Update()
 {
     if (Input.GetMouseButtonUp(0) || Input.GetKeyUp(KeyCode.Space))
     {
         OnJump?.Invoke();
     }
 }
예제 #6
0
    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();
                }
            }
        }
    }
예제 #7
0
 private void Jump(InputAction.CallbackContext context)
 {
     if (OnGround())
     {
         _rigidbody.AddForce(transform.up * _jumpForce, ForceMode2D.Impulse);
         OnJump?.Invoke();
     }
 }
예제 #8
0
        /// <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
        }
예제 #9
0
        private void CheckJumping()
        {
            if (!_lastFrameJumpState && _jumper.Jumping)
            {
                OnJump?.Invoke();
            }

            _lastFrameJumpState = _jumper.Jumping;
        }
예제 #10
0
 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);
     }
 }
예제 #11
0
 private void Update()
 {
     Horizontal = Input.GetAxis("Horizontal");
     Vertical   = Input.GetAxis("Vertical");
     IsRunning  = Input.GetButton("Fire1");
     if (Input.GetButtonDown("Jump"))
     {
         OnJump?.Invoke();
     }
 }
예제 #12
0
 public void Jump()
 {
     if (CanJump())
     {
         return;
     }
     speed.y = jump_impulsion_speed;
     _physicsHandler.VerticalSpeed = speed.y;
     Jump_count++;
     isJumping = true;
     OnJump?.Invoke();
 }
예제 #13
0
    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);
            }
        }
    }
예제 #14
0
        public void JumpFrames(long frameDelta)
        {
            if (VideoTexture == null || frameDelta == 0)
            {
                return;
            }

            var nextFrame = CurrentFrame + frameDelta;

            OnJump?.Invoke();
            SeekFrame(nextFrame);
        }
예제 #15
0
    // 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;
        }
    }
예제 #16
0
        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();
            }
        }
예제 #17
0
    internal void Jump()
    {
        if (OnJump == null)
        {
            return;
        }
        if (!AllowMovement)
        {
            return;
        }

        OnJump.Invoke();
    }
예제 #18
0
    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;
        }
    }
예제 #21
0
        private void Update()
        {
            Horizontal = Input.GetAxis("Horizontal");

            if (Input.GetButtonDown("Jump"))
            {
                OnJump?.Invoke();
            }

            if (Input.GetButtonDown("Switch"))
            {
                OnSwitch?.Invoke();
            }
        }
예제 #22
0
 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;
 }
예제 #23
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);
 }
예제 #24
0
    /// <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;
    }
예제 #25
0
    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();
    }
예제 #27
0
    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;
    }
예제 #28
0
    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();
        }
    }
예제 #29
0
    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();
        }
    }