Exemple #1
0
    // Try to jump with the given velocity.
    // Returns true if the jump successfully executed and false if it did not.
    public bool TryJump(float jumpVelocity)
    {
        if (groundChecker.IsOnGround() && jumpCooldown == 0)
        {
            StartJumpCooldown();

            Vector2 velocity = upDirection.SpaceEnter(rb.velocity);
            velocity.y += jumpVelocity;
            rb.velocity = upDirection.SpaceExit(velocity);

            return(true);
        }
        return(false);
    }
Exemple #2
0
 public override void ReceiveInput(InputReader inputReader)
 {
     if (inputReader.GetKeyUp(KeyCode.Space))
     {
         if (!variableJumped)
         {
             Vector2 velocity = upDirection.SpaceEnter(rb.velocity);
             if (velocity.y > 0.0f)
             {
                 velocity.y    *= variableJumpDampFactor;
                 rb.velocity    = upDirection.SpaceExit(velocity);
                 variableJumped = true;
             }
         }
     }
 }
Exemple #3
0
    private void FixedUpdate()
    {
        Vector2 velocity = upDirection.SpaceEnter(rb.velocity);
        float   dt       = timeScale.DeltaTime();

        // Decelerate if the Rigidbody is grounded and not accelerating.
        if (groundChecker.IsOnGround() && accumulatedHorizontalAcceleration == 0.0f)
        {
            velocity.x = UtilMath.Approach(velocity.x, 0.0f, groundDeceleration * dt);
        }

        // Accelerate the Rigidbody based on applied forces.
        velocity.x += accumulatedHorizontalAcceleration * dt;
        accumulatedHorizontalAcceleration = 0.0f;

        // Cap the Rigidbody's velocity.
        if (Mathf.Abs(velocity.x) > maxHorizontalSpeed)
        {
            velocity.x = Mathf.Sign(velocity.x) * maxHorizontalSpeed;
        }

        rb.velocity = upDirection.SpaceExit(velocity);
    }
Exemple #4
0
 // Sets the GameObject's velocity relative to up space.
 public void SetVelocity(Vector2 vel)
 {
     mover.SetVelocity(upDirection.SpaceExit(vel));
 }