so i’m having a bit of an issue here,i’m completely new to coding and Unity in general, so i’ve been following this tutorial
to learn how to do the basics. everything works at it should. He plays the falling animation when he falls, landing animation when he lands and he walks back and forth.
except he doesn’t jump and i have no idea why. I’ve checked and rewritten the code multiple times but it never works. here’s the code, I did everything exactly as in the video but there’s no result on the jumping. Maybe i’m just missing something really obvious here. Any help is appreciated.
//movement variables
public float maxspeed;
//jumping variables
bool grounded = false;
float groundCheckRadius = 0.2f;
public LayerMask groundLayer;
public Transform groundCheck;
public float jumpHeight;
Rigidbody2D myRB;
Animator myAnim;
bool facingRight;
// Use this for initialization
void Start() {
myRB = GetComponent<Rigidbody2D>();
myAnim = GetComponent<Animator>();
facingRight = true;
}
// Update is called once per frame
void update() {
if (grounded && Input.GetAxis("Jump")>0) {
grounded = false;
myAnim.SetBool("isGrounded",grounded);
myRB.AddForce(new Vector2(0, jumpHeight));
}
}
void FixedUpdate() {
// check if we are grounded if no - then we are falling
grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, groundLayer);
myAnim.SetBool("isGrounded", grounded);
myAnim.SetFloat("verticalSpeed", myRB.velocity.y);
float move = Input.GetAxis("Horizontal");
myAnim.SetFloat("speed", Mathf.Abs(move));
myRB.velocity = new Vector2(move * maxspeed, myRB.velocity.y);
if (move > 0 && !facingRight)
{
flip();
}
else if (move < 0 && facingRight)
{
flip();
}
}
void flip() {
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}