title: Knocking back the Player in a Unity 2D TopDown Game
body: <p>When something hits the Player, maybe an enemy or spikes etc., I want him to get knocked back in the oppisite direction of the enemy.</p>
  
  <p>So what I already got:</p>
  
  <pre><code>public void ChangeHealth(float healthToAdd, Vector2 objectPosition) // Change the players health, objectPosition = enemies position or something else
      {
          if (healthToAdd &lt; 0) // incoming damage
          {
              // ... other stuff
  
              Knockback(objectPosition);
          }
  
          // ... other stuff
      }
  
      void Knockback(Vector2 objectPosition) // Knockback routine
      {
          Vector2 knockbackPosition = new Vector2( , ); // calculation is missing here! Calculate the new position by the knockback direction
  
          rigid.MovePosition(Vector2.MoveTowards(playerPos, knockbackPosition, 2 * Time.deltaTime)); // the knock back
      }
  
      private void Update() // !! TEST !!
      {
          if (Input.GetKeyDown(KeyCode.E)) // TEST routine
          {
              ChangeHealth(-7, new Vector2(10,10)); // decrease players health by 7 and knock him back
          }
      }
  </code></pre>
  
  <p>And what is missing:</p>
  
  <pre><code>Vector2 knockbackPosition = new Vector2( , );
  </code></pre>
  
  <p>I am looking for a calculation like this picture is showing:</p>
  
  <p><a href="https://i.stack.imgur.com/fC9S9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fC9S9.png" alt="enter image description here"></a></p>