title: How to check ground for unity2d platformer game
body: <p>I am trying to make a 2d plat-former where you see the player from the side. I want him to be continuously moving and you have to press space at the right time so he doesn't fall. Right now everything works but he doesn't collide with the ground. I want it to be like he's running behind a wall so I want to ignore a certain layer I have made and collide with the boxes below that. So far I have tried ray casting, watched multiple tutorials, and did box collisions. Box collisions worked but to get all the platforms counted as solid I'd need like 50 box colliders. Here is my current code:</p>
  
  <pre><code>public int playerSpeed = 10;
      public int playerJumpPower = 1250;
      public float moveX;
      public float playerYSize = 2;
      public LayerMask mainGround;
      public float playerFallSpeed = 5;
  
      void Awake(){
  
      }
  
      // Update is called once per frame
      void Update()
      {
          RaycastHit2D hit = Physics2D.Raycast(transform.position, new Vector2(10, 0));
          if(hit.distance &lt; 0.7f){
              print("hi");
          }
  
          Vector3 characterTargetPosition = new Vector3(transform.position.x + playerSpeed, transform.position.y, transform.position.z);
          transform.position = Vector3.Lerp(transform.position, characterTargetPosition, playerSpeed * Time.deltaTime);
  
          if(Input.GetKeyDown("space")){
              // float playerTargetPosY = transform.position.y + playerJumpPower;
              // Vector3 characterTargetPosition = new Vector3(transform.position.x, playerTargetPosY, transform.position.z);
              // transform.position = Vector3.Lerp(transform.position, characterTargetPosition, playerJumpPower * Time.deltaTime);
  
              gameObject.GetComponent&lt;Rigidbody2D&gt;().AddForce(Vector2.up * playerJumpPower);
          }
          //PlayerMove();
      }
  </code></pre>
  
  <p>I have a rigidBody2D on my player so right now he just falls through the ground but the jump does work. If there is any easy way to do this. Like some script, a tutorial, or website I'm open for it. Please help.</p>