title: Unity: knockback in all directions
body: <p>I want to make my player bounce in all directions when it collides with my object, I know that when it hit the left side of my object my player gets knock back to the left and the same with the right side, but how can I include the top and bottom of my object. If I'm not making any sense please look at these pictures (X=0 Y=1) and (X=0 Y=-1). (<a href="http://noobtuts.com/content/unity/2d-pong-game/vector2_directions.png" rel="nofollow">http://noobtuts.com/content/unity/2d-pong-game/vector2_directions.png</a>)</p>
  
  <pre><code> public float xForceToAdd;
   public float yForceToAdd;
   // Use this for initialization
   void Start () {
  
    }
  
    // Update is called once per frame
     void Update () {
  
      }
     void OnTriggerEnter2D(Collider2D other)  {
       if (other.gameObject.tag == "Player")
       {
         //Store the vector 2 of the location where the initial hit happened;
         Vector2 initialHitPoint = new Vector2 (other.gameObject.transform.position.x, other.gameObject.transform.position.y);
         float xForce = 0;
         float yForce = 0;
          //Grab our collided with objects rigibody
        Rigidbody2D rigidForForce = other.gameObject.GetComponent&lt;Rigidbody2D&gt;();
         //Determine left right center of X hit
         if (initialHitPoint.x &gt; (this.transform.position.x + (this.transform.localScale.x /3)))
          {
           xForce = 1;
         }
         else if (initialHitPoint.x &lt; (this.transform.position.x - (this.transform.localScale.x /3)))
         {
           xForce = -1;
         }
        else
         {
            xForce = 0;
         }
         if (initialHitPoint.y &gt; (this.transform.position.y + (this.transform.localScale.y /3)))
         {
            yForce = 1;
         }
        else if (initialHitPoint.y &lt; (this.transform.position.y - (this.transform.localScale.y /3)))
         {
            yForce = -1;
         }
        else
         {
            yForce = 0;
         }
         rigidForForce.velocity = new Vector2(xForce * xForceToAdd, yForce * yForceToAdd);
     }
  
  }
  </code></pre>