Currently, I am programming a 2D Platformer and need to get the Player to be able to jump. Right now, the jumping works well, and so I have moved on to preventing the player jumping whilst in the air. I have used raycasting before and usually, it works well, but I have never tried using it in the 2D version. I am using C#, and would appreciate any help that is given. This is my code so far:
RaycastHit hit;
Ray groundingRay = new Ray(transform.position, -transform.up);
Debug.DrawRay(transform.position, -transform.up * jumpRayLength, Color.blue);
if(Physics.Raycast(groundingRay, out hit, jumpRayLength)) {
if(hit.collider.tag == "Ground") {
isGrounded = true;
isJumping = false;
}
The Problem, that I have found, is that it is not registering colliding with another GameObject. Please note that I have checked that the target object IS tagged.