Hello, im new in unity. So im still learning, im working right now on a 2D game. Im new to Rigidbody2D and velocity. So i just used it to make my player move. and this is the code for it:
rb.velocity = new Vector2(speed * Input.GetAxis(“Horizontal”) * Time.fixedDeltaTime, rb.velocity.y);
as i learned this code has to be in the FixedUpdate methode. to make the movement better. so everything is working as i learned. But i got a problem which is when i click on the console window while the game is on, and then back to the game window. Then my player does not move. Everything else work. Like when i press on the keyboard. (Right Arrow and left Arrow) the player does not move. but the flipX works well. so my player become unable to move. but when i press on space to make the player jump, then i can move as it should be. in the beginning i thought the problem was because the game goes to unfocus mode and then back to focus mode and that makes the fixedUpdate methode dont work. But then i realized that while im testing the level i have made, so i get the same problem. The player sometimes just doesnt move. like its stuck, and when i press on Left Arrow or Right Arrow the player flips. And when the player jumps, then the movement works again.
Please help guys im just stuck on it and i cant learn something new because of thinking about this issue.
( rb.velocity = new Vector2(speed * Input.GetAxis(“Horizontal”) * Time.fixedDeltaTime, rb.velocity.y)
TO MAKE THE PLAYER MOVE
(rb.velocity = new Vector2(0, jump)
to make the player JUMP.