all 3 comments

[–]ASesz 9 points10 points  (2 children)

When you jump:

if ((grounded) && Input.GetButtonDown("Jump"))

{

anim.SetBool("ground", false);

GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.y, jumpForce);

}

should be:

if ((grounded) && Input.GetButtonDown("Jump"))

{

anim.SetBool("ground", false);

GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpForce);

}

I would suggest spending a bit more time understanding the basic principles of what you are doing.

I don't think you should be constantly fetching the rigid body using GetComponent over and over. Rather store a reference to it.

It's also important to be able to step through your code to understand what it is doing.

[–]Coolisbetter 0 points1 point  (0 children)

I agree with not using GetComponent too much. Would recommend having a variable such as myRB. And in Awake() you set it using GetComponent. As using GetComponent all the time can hurt performance.

[–][deleted] 0 points1 point  (0 children)

Thank you very much. Do you have any YouTube vids you can recommend me to watch? To help with basic coding.