when i jump and move in air its falling very slow and its annoying and i cant fix it please help.
my code is here:
public Rigidbody2D rb2D;
public float playerSpeed;
public float maxSpeedForPlayer;
public float jumpForce = 2f;
public Vector3 jump;
public bool isGrounded;
private void Start()
{
rb2D = GetComponent<Rigidbody2D>();
jump = new Vector2(0f, 2f);
}
//Jumping
private void OnCollisionStay2D()
{
isGrounded = true;
}
private void OnCollisionExit2D()
{
isGrounded = false;
}
//Input and movement
private void Update()
{
if (Input.GetKey(KeyCode.D))
{
rb2D.velocity = new Vector3(maxSpeedForPlayer, 0, 0);
rb2D.AddForce(new Vector3(playerSpeed, 0f, 0f));
}
if (Input.GetKey(KeyCode.A))
{
rb2D.velocity = new Vector3(maxSpeedForPlayer, 0, 0);
rb2D.AddForce(new Vector3(-playerSpeed, 0f, 0f));
}
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
rb2D.AddForce(jump * jumpForce, ForceMode2D.Impulse);
isGrounded = false;
}
}
}