void FixedUpdate() { if (body.collisionState.above || body.collisionState.below) { velocity.y = 0.0f; } if (body.collisionState.left || body.collisionState.right) { velocity.x = 0.0f; } //Add gravity float lowGravityThreshold = apexLowGravityVelocityRange; if (velocity.y < -lowGravityThreshold) { velocity.y += gravity * landingGravityModifier * Time.deltaTime; } else { if (JumpPressed) { velocity.y += gravity * variableJumpGravityModifier * Time.deltaTime; } else { if (Math.Abs(velocity.y) < lowGravityThreshold) { velocity.y += gravity * variableJumpGravityModifier * Time.deltaTime; } else { velocity.y += gravity * Time.deltaTime; } } } if (JumpPressed) { jumpBuffer = jumpBufferTime; } if (jumpBuffer > 0.0f) { if (body.collisionState.below) { velocity.y = jumpVelocity; } jumpBuffer -= Time.deltaTime; } //float targetX = Input.GetAxisRaw("Horizontal") * runMaxSpeed; float targetX = InputX * runMaxSpeed; float currentAcceleration = runAcceleration; velocity.x = Mathf.MoveTowards(velocity.x, targetX, currentAcceleration * Time.deltaTime); velocity += velocityBuffer; velocityBuffer = Vector2.zero; body.Move(velocity * Time.deltaTime); }