title: Unity determining ground via raycasting 2d
body: <p>Good evening!</p>
  
  <p>I am trying to make a simple 2d platformer in unity without using rigidbodies, so I use raycast to determine where is the ground. I wrote this code:</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class comtroller : MonoBehaviour
  {
  
      private float velocity_y;
      private float velocity_x;
  
      private float speed_y = 1;
      private float speed_x = 10;
  
      private float localMinimum_y;
  
  
  
      //mask of the platform
      public LayerMask mask;
  
      void Update()
      {
  
          // raycast to sense platforms
          RaycastHit2D hit = Physics2D.Raycast((Vector2)transform.position , Vector2.down,Mathf.Infinity, mask);
  
          if (hit)
          {
              localMinimum_y = hit.point.y;
          }
          else
          {
              localMinimum_y = -10;
          }
  
  
          //determine whether the player can fall down
          // -0.6 is the distance between the player's transform.position and his legs
          if(transform.position.y -0.6f &lt; localMinimum_y)
          {
              speed_y = 0;
          }
          else
          {
              speed_y = 1;
          }
  
  
          //determine velocities
  
          velocity_y = speed_y * Physics2D.gravity.y * Time.deltaTime;
          velocity_x = Input.GetAxis("Horizontal") * speed_x * Time.deltaTime;
  
  
          //movement
          transform.Translate(new Vector2(velocity_x, velocity_y));
      }
  
  
  
  
  }
  </code></pre>
  
  <p>However, the player keeps stucking in the platform.
  Can anyone help me where is the problem and how can I cure it?
  Or if my idea is completely bad can you give any suggestion about how to do it?
  Thank you</p>