title: Trying to create a nice character controller?
body: <p>I'm kind of new in the 2D environment of Unity.</p>
  
  <p>I'm trying to create a platformer. For now, I have a simple map and my player.</p>
  
  <p><a href="https://i.stack.imgur.com/H4Phz.png" rel="nofollow noreferrer">My simple map and my player</a></p>
  
  <p>My player have one script attached : </p>
  
  <pre><code>public class Player : MonoBehaviour
  {
      public float speed;
      public float jump;
      public GameObject raycastPoint; // Positioned at 0.01 pixel below the player
  
      private SpriteRenderer spriteRenderer;
      private Rigidbody2D body; // Gravity Scale of the Rigidbody2D = 50
      private Animator animator;
  
      private void Start()
      {
          spriteRenderer = GetComponent&lt;SpriteRenderer&gt;();
          body = GetComponent&lt;Rigidbody2D&gt;();
          animator = GetComponent&lt;Animator&gt;();
      }
  
      private void Update()
      {
          float horizontal = Input.GetAxisRaw("Horizontal");
  
          if (horizontal == 1 &amp;&amp; spriteRenderer.flipX)
          {
              spriteRenderer.flipX = false;
          }
          else if (horizontal == -1 &amp;&amp; !spriteRenderer.flipX)
          {
              spriteRenderer.flipX = true;
          }
  
          body.velocity = new Vector2(horizontal * speed, body.velocity.y);
  
          animator.SetFloat("Speed", Mathf.Abs(horizontal));
  
          float vertical = Input.GetAxisRaw("Vertical");
  
          if (vertical == 1)
          {
              RaycastHit2D hit = Physics2D.Raycast(raycastPoint.transform.position, Vector2.down, 0.01f);
  
              if (hit.collider != null)
              {
                  body.AddForce(new Vector2(0f, jump));
              }
          }
      }
  }
  </code></pre>
  
  <p>For now I have achieved the right and left movements.</p>
  
  <p>For the jump, I have a child gameobject just under the player and I'm firing a raycast to the bottom so I can know if my player is grounded or not.</p>
  
  <p>I have two problems.</p>
  
  <p>PROBLEM NUMBER ONE.</p>
  
  <p>Sometimes I feel like my "AddForce" line is executed multiple times my player is jumping really high</p>
  
  <p><a href="https://i.stack.imgur.com/9U48k.png" rel="nofollow noreferrer">Problem number one image</a></p>
  
  <p>PROBLEM NUMBER TWO.</p>
  
  <p>When I'm jumping to the left or right wall, if I keep pressing the left or right key my player is not falling anymore and stay against the wall.</p>
  
  <p><a href="https://i.stack.imgur.com/AbriG.png" rel="nofollow noreferrer">Problem number two image</a></p>
  
  <p>I tried to put my code into the FixedUpdate method (I know it's better) but I had the same results.</p>
  
  <p>And I tried to set the Collision Detection on Continuous but I had the same results.</p>