Gravity won't apply after I hit jump, just floats up
Every time I hit the jump button it just keeps floating up. I can't quite figure out what to put to access the gravity and physics.
void FixedUpdate()
{
Vector2 temp = new Vector2(); //create a temporary (temp) vector2 for holding our velocity changes
temp.x = curMovement; //Assign our current movement information to the temp velocity variable
grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround); //cast a circle around the ground check point to check for a ground object
//jump logic
if (jumpInit)
{
jumpInit = true; //jump has been initialized, we don't need this to be anymore.
temp.y = jumpVelocity; //apply the jump velocity to the up and down (y) axis of our temp variable
}
else //if not jumping, then keep our current velocity
// access gravity and vector here?
if (rb.velocity.y < 0)
{
rb.velocity -= Vector2.up * Physics2D.gravity.y * fallMultiplier * Time.fixedDeltaTime;
//Vector2.up * Physics2D.gravity.y = (0, -9.81) * 1.5 = (0, -14.715)
}
else if (rb.velocity.y > 0 && !jumpButton) //if no longer holding jump, fall sooner
{
rb.velocity -= Vector2.up * Physics2D.gravity.y * lowJumpMultiplier * Time.fixedDeltaTime;
//Vector2.up * Physics2D.gravity.y = (0, -9.81) * 1 = (0, -9.81)
}
rb.velocity = temp; //apply our velocity changes all at once
}
}
Comment