Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

My character double jumps if he runs, before jumping??

$
0
0
I want my character to just jump once, and it works as long as he doesn't run. If just stand there and jump, he can only do it once (until he collides with the ground again), but if he runs, and then jumps he can make an extra jump before unable to jump again. I have NO idea why. Can anyone here help? Here's the part of the code: void Update () { if(Input.GetKey(KeyCode.RightArrow)) { transform.Translate(Vector2.right * Time.deltaTime*speed); transform.localScale = new Vector3(1, 1, 1); } if (Input.GetKey(KeyCode.LeftArrow)) { transform.Translate(-Vector2.right * Time.deltaTime * speed); transform.localScale = new Vector3(-1, 1, 1); } if (isTouchingGround==true) { if (Input.GetKeyDown(KeyCode.UpArrow)) { rigidbody2D.AddForce(Vector2.up * jumpForce); isTouchingGround = false; } } void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.tag == "Ground") isTouchingGround = true; }

Viewing all articles
Browse latest Browse all 1264

Trending Articles