hello guys so i was making a 2D game and i was trying to make my player jump. so I wrote:
float j = Input.GetAxis(“Jump”);
rb.velocity = new Vector2(rb.velocity.x, j x(multiply) Time.deltaTime x MoveSpeed);
MoveSpeed is a speed variable I created to change in unity inspector below script’s options.
when I use this code my player jumps successfully but when landing he/she lands very slowly, like floating. how do i fix this and what is the problem in this code?
- Watch some tutorials, search in youtube ‘‘Player Movement Script + My game gendre (Ex; Platformer 2D)’’
- If you’re going to move using transform.translate stick to it, but i’d rather recommend you to use rigidbody in both the movement and jumping methods.
- To move or Jump with a rigidbody you add a certain force to the rigidbody, is like you push it to the direction you want, by doing translate you teleport it in a veery small amount to the direction you want.
- In Physics you don’t need to use DeltaTime at least not for that kind of thing because they must work evenly despite the conditions or something like that idk.
- to add this force you simply tweek the velocity, you must have an if statement that gets called when the input was pressed and then put
rb.velocity = new Vector2(rb.velocity.x, jumpForce);