# Why do I glide in the air when I move my player, and why can't I jump while I'm moving left or right

When I move my game character in the air, I start gliding and moving down very slowly.

Here’s my movement/jump code:

``````public class playerScript : MonoBehaviour
{

public Rigidbody2D jimmy_Rigidbody;
public float moveSpeed;
public float jumpStrength;
private bool canJump;
private bool isMoving;

// Start is called before the first frame update
void Start()
{
canJump = false;
}

// Update is called once per frame
void Update()
{
isMoving = false;
if (Input.GetKey(KeyCode.RightArrow))
{
isMoving = true;
jimmy_Rigidbody.velocity = Vector2.right * moveSpeed;
isMoving = false;
}
if (Input.GetKey(KeyCode.LeftArrow))
{
isMoving = true;
jimmy_Rigidbody.velocity = Vector2.left * moveSpeed;
isMoving = false;
}
if (canJump == true)
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
jimmy_Rigidbody.velocity = Vector2.up * jumpStrength;
canJump = false;
}
}
}

void OnCollisionStay2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("ground"))
{
canJump = true;
}
}
}
``````

Both your jump code and your left/right movement code set both X and Y of the Rigidbody velocity. On the frame where you jump, this line will take precedence over your left/right movement:

``````jimmy_Rigidbody.velocity = Vector2.up * jumpStrength;
``````

Vector2.up has 0 for x, so there will be no horizontal movement on that frame.

Similarly, when you are in the air, your left/right movement code is forcing the y velocity to 0. Since this runs on `Update`, not `FixedUpdate`, the physics engine is still able to apply gravity for a small period of time before your code here forces the y velocity to 0 again.

It may be better to determine the desired velocity in a separate variable and only apply the velocity to the rigid body after you have made all of your adjustments. X and Y movement can be separated. Also, since you are modifying the rigidbody, this should be done in `FixedUpdate` rather than `Update`.

``````void FixedUpdate()
{
Vector2 targetV = jimmy_Rigidbody.velocity;
isMoving = false;
if (Input.GetKey(KeyCode.RightArrow))
{
isMoving = true;
targetV.x = moveSpeed;
isMoving = false;
}
if (Input.GetKey(KeyCode.LeftArrow))
{
isMoving = true;
targetV.x = -moveSpeed;
isMoving = false;
}
if (canJump == true)
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
targetV.y = jumpStrength;
canJump = false;
}
}
jimmy_Rigidbody.velocity = targetV;
}
``````

You can also try using the AddForce() method, that way you can apply momentum to the jump action while using gravity on your set parameters.