Esempio n. 1
0
    private void FixedUpdate()
    {
        Vector2 velocity = vius.GetVelocity();

        velocity.y -= acceleration * gravityScale * timeScale.DeltaTime();
        vius.SetVelocity(velocity);
    }
Esempio n. 2
0
    private void GroundLanded()
    {
        gravity.enabled = false;
        Vector2 velocity = vius.GetVelocity();

        velocity.y = 0.0f;
        vius.SetVelocity(velocity);
    }
Esempio n. 3
0
    public void Tick(float deltaTime)
    {
        if (!enabled)
        {
            return;
        }
        Vector2 velocity = vius.GetVelocity();

        velocity.y -= acceleration * deltaTime;
        vius.SetVelocity(velocity);
    }
    // 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 = vius.GetVelocity();
            velocity.y += jumpVelocity;
            vius.SetVelocity(velocity);
            OnJumped(jumpVelocity);

            return(true);
        }
        return(false);
    }
Esempio n. 5
0
 public override void ReceiveInput(InputReader inputReader)
 {
     if (inputReader.GetKeyUp(KeyCode.Space))
     {
         if (!variableJumped)
         {
             Vector2 velocity = vius.GetVelocity();
             if (velocity.y > 0.0f)
             {
                 velocity.y *= variableJumpDampFactor;
                 vius.SetVelocity(velocity);
                 // Variable jump executed successfully.
                 variableJumped = true;
             }
         }
     }
 }
 //public override void ReceiveInput(InputReader inputReader)
 public void Tick()
 {
     if (Input.GetKeyUp(buttonJump))
     {
         // Do not allow variable jumping in zero gravity.
         if (!variableJumped && gravity.GetAcceleration() != 0.0f)
         {
             Vector2 velocity = vius.GetVelocity();
             if (velocity.y > 0.0f)
             {
                 velocity.y *= variableJumpDampFactor;
                 vius.SetVelocity(velocity);
                 // Variable jump executed successfully.
                 variableJumped = true;
             }
         }
     }
 }
Esempio n. 7
0
    public void Tick(float deltaTime)
    {
        Vector2 velocity = vius.GetVelocity();

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

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

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

        vius.SetVelocity(velocity);
    }