When I am moving the player and jump to a wall to intentionally collide it, it sticks to it until I release the Key I use to move it and also Im able to jump until I hit have another collide on topside of the player
Here is the code I am using for this (everything is on void Update())
IsGrounded = Physics2D.OverlapCircle (GroundChecker.position, RadiusOfChecker, GroundLayer); //Check if the player is colliding in feet position using a circle.
Walking = (Input.GetKey (KeyCode.LeftArrow) &&Input.GetKeyDown (KeyCode.LeftArrow) && !OnAnimation) ? true : false; // Check if player is walking
if (Input.GetKey (KeyCode.RightArrow )&& !OnAnimation) {
GetComponent<Rigidbody2D> ().velocity = new Vector2 (MovementSpeed, GetComponent<Rigidbody2D> ().velocity.y); // Move the player right if RightArrow KeyPressed and is not on Animation
FacingRight = true;
}
if (Input.GetKey (KeyCode.LeftArrow)) {
GetComponent<Rigidbody2D> ().velocity = new Vector2 (-MovementSpeed, GetComponent<Rigidbody2D> ().velocity.y);// Move the player left if RightArrow KeyPressed and is not on Animation
FacingRight = false;
}
GetComponent<SpriteRenderer> ().flipX = (FacingRight) ? false:true;
if(Input.GetKeyDown(KeyCode.Space)){
if (IsGrounded && !OnAnimation) {
GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D>().velocity.x,JumpHeight);
JumpsLeft = Extra_Jumps;
}else if ((!OnAnimation && !IsGrounded) && JumpsLeft > 0 ) {
GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D>().velocity.x,JumpHeight);
JumpsLeft--;
}
}
I will be very thankful if someone helps me with this!
Thanks.