Question by 
               Neilk_94 · Mar 31, 2016 at 04:11 PM · 
                unity 52d game2d-platformer2d-physicsjumping  
              
 
              Player can only jump once!?
Hi, so I'm following a 'gameswithjames' tutorial on a 2d platformer. My player could jump fine right up until two minutes ago where I started to add checkpoints and respawning in part 3 of the tutorial.
Now I just get the one jump off and am grounded for ever afterwards. Again, it worked before without changing any of the player movement script. I can't figure out whats changed.
Any help would be appreciated!
 using UnityEngine;
 using System.Collections;
 public class playerController : MonoBehaviour {
 //  basic movement
 public float moveSpeed;
 public float jumpHeight;
 public Transform groundCheck;   //  transform has a location
 public float groundCheckRadius; //  Determines size of circe
 public LayerMask whatIsGround;
 private bool grounded;
 private bool doubleJumped;
 // Use this for initialization
 void Start () {
 
 }
 void FixedUpdate()  //  fixedupdate occurs a set amount of time every second
 {
     grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
 }
 
 // Update is called once per frame
 void Update () {
     if (grounded)
     {
         doubleJumped = false;
     }
     //  Jump
     if(Input.GetKeyDown (KeyCode.Space) && grounded)    //  checks to see if space button is 'keyed' down (pressed) and checks if grounded
     {
         Jump();
     }
     //  Jump
     if (Input.GetKeyDown(KeyCode.Space) && !doubleJumped && !grounded)    //  checks to see if space button is 'keyed' down (pressed) and checks if grounded
     {
         Jump();
         doubleJumped = true;
     }
     //  Move right
     if (Input.GetKey(KeyCode.D))
     {
         GetComponent<Rigidbody2D>().velocity = new Vector2(moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
     }
     //  Move left
     if (Input.GetKey(KeyCode.A))
     {
         GetComponent<Rigidbody2D>().velocity = new Vector2(-moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
     }
 }
 public void Jump()
 {
     GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x,        jumpHeight);
 }
 }
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Broken Jump Physics 0 Answers
How to create a 2D obstacle as a question 0 Answers
Platform Bounce effect 2d 1 Answer
[2D] Make player push object 1 Answer