示例#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);
    }
示例#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;
             }
         }
     }
 }
示例#3
0
    private void FixedUpdate()
    {
        velocityTransformed = upDirection.SpaceEnter(velocityReader.GetVelocity());
        switch (directions)
        {
        case Directions.Horizontal:
            RotateHorizontal();
            break;

        case Directions.Vertical:
            RotateVertical();
            break;

        case Directions.Both:
            RotateHorizontal();
            RotateVertical();
            break;
        }
    }
示例#4
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);
    }
示例#5
0
 // Retrieves the GameObject's velocity relative to up space.
 public Vector2 GetVelocity()
 {
     return(upDirection.SpaceEnter(mover.GetVelocity()));
 }