title: The player moves down Y and falls under the floor
body: <p>please tell me what is the error? I have a player falling down under the floor, the movement on Y is carried out.
  On the player I have Rigidbody2D configured as usual, set “Linear Drag” to 1 and turned on“Freeze Rotation”. And I also added
  CapsuleCollider2D.</p>
  <p><a href="https://i.stack.imgur.com/0O3FW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0O3FW.png" alt="enter image description here" /></a>
  <a href="https://i.stack.imgur.com/RWf9e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RWf9e.png" alt="enter image description here" /></a></p>
  <p>For the floor, I have enabled BoxCollider2D.</p>
  <p><a href="https://i.stack.imgur.com/h4eZz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h4eZz.png" alt="enter image description here" /></a></p>
  <p>I hung this script on the player:</p>
  <pre><code>public class PlayerController : MonoBehaviour
  {
      public PlayerState curState;            // current player state
  
      // values
  public float moveSpeed;                 // force applied horizontally when moving
  public float flyingSpeed;               // force applied upwards when flying
  public bool grounded;                   // is the player currently standing on the ground?
  public float stunDuration;              // duration of a stun
  private float stunStartTime;            // time that the player was stunned
  
  // components
  public Rigidbody2D rig;                 // Rigidbody2D component
  public Animator anim;                   // Animator component
  public ParticleSystem jetpackParticle;  // ParticleSystem of jetpack
  
  void FixedUpdate ()
  {
      grounded = IsGrounded();
      CheckInputs();
  
      // is the player stunned?
      if(curState == PlayerState.Stunned)
      {
          // has the player been stunned for the duration?
          if(Time.time - stunStartTime &gt;= stunDuration)
          {
              curState = PlayerState.Idle;
          }
      }
  }
  
  // checks for user input to control player
  void CheckInputs ()
  {
      if (curState != PlayerState.Stunned)
      {
          // movement
          Move();
  
          // flying
          if (Input.GetKey(KeyCode.UpArrow))
              Fly();
          else
              jetpackParticle.Stop();
      }
  
      // update our current state
      SetState();
  }
  
  // sets the player's state
  void SetState ()
  {
      // don't worry about changing states if the player's stunned
      if (curState != PlayerState.Stunned)
      {
          // idle
          if (rig.velocity.magnitude == 0 &amp;&amp; grounded)
              curState = PlayerState.Idle;
          // walking
          if (rig.velocity.x != 0 &amp;&amp; grounded)
              curState = PlayerState.Walking;
          // flying
          if (rig.velocity.magnitude != 0 &amp;&amp; !grounded)
              curState = PlayerState.Flying;
      }
  
      // tell the animator we've changed states
      anim.SetInteger(&quot;State&quot;, (int)curState);
  }
  
  // moves the player horizontally
  void Move ()
  {
      // get horizontal axis (A &amp; D, Left Arrow &amp; Right Arrow)
      float dir = Input.GetAxis(&quot;Horizontal&quot;);
  
      // flip player to face the direction they're moving
      if (dir &gt; 0)
          transform.localScale = new Vector3(1, 1, 1);
      else if (dir &lt; 0)
          transform.localScale = new Vector3(-1, 1, 1);
  
      // set rigidbody horizontal velocity
      rig.velocity = new Vector2(dir * moveSpeed, rig.velocity.y);
  }
  
  // adds force upwards to player
  void Fly ()
  {
      // add force upwards
      rig.AddForce(Vector2.up * flyingSpeed, ForceMode2D.Impulse);
  
      // play jetpack particle effect
      if (!jetpackParticle.isPlaying)
          jetpackParticle.Play();
  }
  
  // called when the player gets stunned
  public void Stun ()
  {
      curState = PlayerState.Stunned;
      rig.velocity = Vector2.down * 3;
      stunStartTime = Time.time;
      jetpackParticle.Stop();
  }
  
  // returns true if player is on ground, false otherwise
  bool IsGrounded ()
  {
      // shoot a raycast down underneath the player
      RaycastHit2D hit = Physics2D.Raycast(new Vector2(transform.position.x, transform.position.y - 0.85f), Vector2.down, 0.3f);
  
      // did we hit anything?
      if(hit.collider != null)
      {
          // was it the floor?
          if(hit.collider.CompareTag(&quot;Floor&quot;))
          {
              return true;
          }
      }
  
      return false;
  }
  
  // called when the player enters another object's collider
  void OnTriggerEnter2D (Collider2D col)
  {
      // if the player isn't already stunned, stun them if the object was an obstacle
      if(curState != PlayerState.Stunned)
      {
          if(col.CompareTag(&quot;Obstacle&quot;))
          {
              Stun();
          }
      }
  }
  </code></pre>
  <p>}</p>