Detect Collisions with Three Objects












0














I have a block that I'm moving around the level, and I want to make it so that if it hits a corner (ex: top right boundary), it doesn't move anywhere. Regular collision detection doesn't work, because I'm having the block move in short jumps (player.transform.position.x - 1, etc).



Here is the code I'm using:



public void OnCollisionEnter2D(Collision2D collision)
{ if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "top" && GetComponent<BoxCollider2D>().tag == "left"))
{
player.canMoveUp = false;
player.canMoveDown = true;
player.canMoveLeft = false;
player.canMoveRight = true;
}
else if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "top" && GetComponent<BoxCollider2D>().tag == "right"))
{
player.canMoveUp = false;
player.canMoveDown = true;
player.canMoveLeft = true;
player.canMoveRight = false;
}
else if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "bottom" && GetComponent<BoxCollider2D>().tag == "left"))
{
player.canMoveUp = true;
player.canMoveDown = false;
player.canMoveLeft = false;
player.canMoveRight = true;
}
else if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "bottom" && GetComponent<BoxCollider2D>().tag == "right"))
{
player.canMoveUp = true;
player.canMoveDown = false;
player.canMoveLeft = true;
player.canMoveRight = false;
}
}

public void OnCollisionExit2D(Collision2D collision)
{
Debug.Log("notTouching");
player.canMoveUp = true;
player.canMoveDown = true;
player.canMoveLeft = true;
player.canMoveRight = true;
}


EDIT: New code.



 if (Input.GetKeyUp(KeyCode.LeftArrow))
{
Vector2 movementLeft = new Vector2(-1, 0);
RaycastHit2D hitLeft = Physics2D.Raycast(transform.position, movementLeft, -1);

if (hitLeft.collider && hitLeft.collider.gameObject.tag == "barrier")
{
Debug.Log("N/A");
}
else
{
player.transform.position += new Vector3(movementLeft.x,movementLeft.y,0);
}
}
else if (Input.GetKeyUp(KeyCode.RightArrow))
{
Vector2 movementRight = new Vector2(1, 0);
RaycastHit2D hitRight = Physics2D.Raycast(transform.position, movementRight, 1);

if (hitRight.collider && hitRight.collider.gameObject.tag == "barrier")
{
Debug.Log("N/A");
}
else
{
player.transform.position += new Vector3(movementRight.x, movementRight.y, 0);
}
}
else if (Input.GetKeyUp(KeyCode.DownArrow))
{
Vector2 movementDown = new Vector2(0, -1);
RaycastHit2D hitDown = Physics2D.Raycast(transform.position, movementDown, -1);

if (hitDown.collider && hitDown.collider.gameObject.tag == "barrier")
{
Debug.Log("N/A");
}
else
{
player.transform.position += new Vector3(movementDown.x, movementDown.y, 0);
}
}
else if (Input.GetKeyUp(KeyCode.UpArrow))
{
Vector2 movementUp = new Vector2(0, 1);
RaycastHit2D hitUp = Physics2D.Raycast(transform.position, movementUp, 1);

if (hitUp.collider && hitUp.collider.gameObject.tag == "barrier")
{
Debug.Log("N/A");
}
else
{
player.transform.position += new Vector3(movementUp.x, movementUp.y, 0);
}
}
else
{
Debug.Log("N/A");
}









share|improve this question





























    0














    I have a block that I'm moving around the level, and I want to make it so that if it hits a corner (ex: top right boundary), it doesn't move anywhere. Regular collision detection doesn't work, because I'm having the block move in short jumps (player.transform.position.x - 1, etc).



    Here is the code I'm using:



    public void OnCollisionEnter2D(Collision2D collision)
    { if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "top" && GetComponent<BoxCollider2D>().tag == "left"))
    {
    player.canMoveUp = false;
    player.canMoveDown = true;
    player.canMoveLeft = false;
    player.canMoveRight = true;
    }
    else if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "top" && GetComponent<BoxCollider2D>().tag == "right"))
    {
    player.canMoveUp = false;
    player.canMoveDown = true;
    player.canMoveLeft = true;
    player.canMoveRight = false;
    }
    else if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "bottom" && GetComponent<BoxCollider2D>().tag == "left"))
    {
    player.canMoveUp = true;
    player.canMoveDown = false;
    player.canMoveLeft = false;
    player.canMoveRight = true;
    }
    else if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "bottom" && GetComponent<BoxCollider2D>().tag == "right"))
    {
    player.canMoveUp = true;
    player.canMoveDown = false;
    player.canMoveLeft = true;
    player.canMoveRight = false;
    }
    }

    public void OnCollisionExit2D(Collision2D collision)
    {
    Debug.Log("notTouching");
    player.canMoveUp = true;
    player.canMoveDown = true;
    player.canMoveLeft = true;
    player.canMoveRight = true;
    }


    EDIT: New code.



     if (Input.GetKeyUp(KeyCode.LeftArrow))
    {
    Vector2 movementLeft = new Vector2(-1, 0);
    RaycastHit2D hitLeft = Physics2D.Raycast(transform.position, movementLeft, -1);

    if (hitLeft.collider && hitLeft.collider.gameObject.tag == "barrier")
    {
    Debug.Log("N/A");
    }
    else
    {
    player.transform.position += new Vector3(movementLeft.x,movementLeft.y,0);
    }
    }
    else if (Input.GetKeyUp(KeyCode.RightArrow))
    {
    Vector2 movementRight = new Vector2(1, 0);
    RaycastHit2D hitRight = Physics2D.Raycast(transform.position, movementRight, 1);

    if (hitRight.collider && hitRight.collider.gameObject.tag == "barrier")
    {
    Debug.Log("N/A");
    }
    else
    {
    player.transform.position += new Vector3(movementRight.x, movementRight.y, 0);
    }
    }
    else if (Input.GetKeyUp(KeyCode.DownArrow))
    {
    Vector2 movementDown = new Vector2(0, -1);
    RaycastHit2D hitDown = Physics2D.Raycast(transform.position, movementDown, -1);

    if (hitDown.collider && hitDown.collider.gameObject.tag == "barrier")
    {
    Debug.Log("N/A");
    }
    else
    {
    player.transform.position += new Vector3(movementDown.x, movementDown.y, 0);
    }
    }
    else if (Input.GetKeyUp(KeyCode.UpArrow))
    {
    Vector2 movementUp = new Vector2(0, 1);
    RaycastHit2D hitUp = Physics2D.Raycast(transform.position, movementUp, 1);

    if (hitUp.collider && hitUp.collider.gameObject.tag == "barrier")
    {
    Debug.Log("N/A");
    }
    else
    {
    player.transform.position += new Vector3(movementUp.x, movementUp.y, 0);
    }
    }
    else
    {
    Debug.Log("N/A");
    }









    share|improve this question



























      0












      0








      0







      I have a block that I'm moving around the level, and I want to make it so that if it hits a corner (ex: top right boundary), it doesn't move anywhere. Regular collision detection doesn't work, because I'm having the block move in short jumps (player.transform.position.x - 1, etc).



      Here is the code I'm using:



      public void OnCollisionEnter2D(Collision2D collision)
      { if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "top" && GetComponent<BoxCollider2D>().tag == "left"))
      {
      player.canMoveUp = false;
      player.canMoveDown = true;
      player.canMoveLeft = false;
      player.canMoveRight = true;
      }
      else if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "top" && GetComponent<BoxCollider2D>().tag == "right"))
      {
      player.canMoveUp = false;
      player.canMoveDown = true;
      player.canMoveLeft = true;
      player.canMoveRight = false;
      }
      else if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "bottom" && GetComponent<BoxCollider2D>().tag == "left"))
      {
      player.canMoveUp = true;
      player.canMoveDown = false;
      player.canMoveLeft = false;
      player.canMoveRight = true;
      }
      else if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "bottom" && GetComponent<BoxCollider2D>().tag == "right"))
      {
      player.canMoveUp = true;
      player.canMoveDown = false;
      player.canMoveLeft = true;
      player.canMoveRight = false;
      }
      }

      public void OnCollisionExit2D(Collision2D collision)
      {
      Debug.Log("notTouching");
      player.canMoveUp = true;
      player.canMoveDown = true;
      player.canMoveLeft = true;
      player.canMoveRight = true;
      }


      EDIT: New code.



       if (Input.GetKeyUp(KeyCode.LeftArrow))
      {
      Vector2 movementLeft = new Vector2(-1, 0);
      RaycastHit2D hitLeft = Physics2D.Raycast(transform.position, movementLeft, -1);

      if (hitLeft.collider && hitLeft.collider.gameObject.tag == "barrier")
      {
      Debug.Log("N/A");
      }
      else
      {
      player.transform.position += new Vector3(movementLeft.x,movementLeft.y,0);
      }
      }
      else if (Input.GetKeyUp(KeyCode.RightArrow))
      {
      Vector2 movementRight = new Vector2(1, 0);
      RaycastHit2D hitRight = Physics2D.Raycast(transform.position, movementRight, 1);

      if (hitRight.collider && hitRight.collider.gameObject.tag == "barrier")
      {
      Debug.Log("N/A");
      }
      else
      {
      player.transform.position += new Vector3(movementRight.x, movementRight.y, 0);
      }
      }
      else if (Input.GetKeyUp(KeyCode.DownArrow))
      {
      Vector2 movementDown = new Vector2(0, -1);
      RaycastHit2D hitDown = Physics2D.Raycast(transform.position, movementDown, -1);

      if (hitDown.collider && hitDown.collider.gameObject.tag == "barrier")
      {
      Debug.Log("N/A");
      }
      else
      {
      player.transform.position += new Vector3(movementDown.x, movementDown.y, 0);
      }
      }
      else if (Input.GetKeyUp(KeyCode.UpArrow))
      {
      Vector2 movementUp = new Vector2(0, 1);
      RaycastHit2D hitUp = Physics2D.Raycast(transform.position, movementUp, 1);

      if (hitUp.collider && hitUp.collider.gameObject.tag == "barrier")
      {
      Debug.Log("N/A");
      }
      else
      {
      player.transform.position += new Vector3(movementUp.x, movementUp.y, 0);
      }
      }
      else
      {
      Debug.Log("N/A");
      }









      share|improve this question















      I have a block that I'm moving around the level, and I want to make it so that if it hits a corner (ex: top right boundary), it doesn't move anywhere. Regular collision detection doesn't work, because I'm having the block move in short jumps (player.transform.position.x - 1, etc).



      Here is the code I'm using:



      public void OnCollisionEnter2D(Collision2D collision)
      { if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "top" && GetComponent<BoxCollider2D>().tag == "left"))
      {
      player.canMoveUp = false;
      player.canMoveDown = true;
      player.canMoveLeft = false;
      player.canMoveRight = true;
      }
      else if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "top" && GetComponent<BoxCollider2D>().tag == "right"))
      {
      player.canMoveUp = false;
      player.canMoveDown = true;
      player.canMoveLeft = true;
      player.canMoveRight = false;
      }
      else if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "bottom" && GetComponent<BoxCollider2D>().tag == "left"))
      {
      player.canMoveUp = true;
      player.canMoveDown = false;
      player.canMoveLeft = false;
      player.canMoveRight = true;
      }
      else if (collision.gameObject.tag == "barrier" && (GetComponent<BoxCollider2D>().tag == "bottom" && GetComponent<BoxCollider2D>().tag == "right"))
      {
      player.canMoveUp = true;
      player.canMoveDown = false;
      player.canMoveLeft = true;
      player.canMoveRight = false;
      }
      }

      public void OnCollisionExit2D(Collision2D collision)
      {
      Debug.Log("notTouching");
      player.canMoveUp = true;
      player.canMoveDown = true;
      player.canMoveLeft = true;
      player.canMoveRight = true;
      }


      EDIT: New code.



       if (Input.GetKeyUp(KeyCode.LeftArrow))
      {
      Vector2 movementLeft = new Vector2(-1, 0);
      RaycastHit2D hitLeft = Physics2D.Raycast(transform.position, movementLeft, -1);

      if (hitLeft.collider && hitLeft.collider.gameObject.tag == "barrier")
      {
      Debug.Log("N/A");
      }
      else
      {
      player.transform.position += new Vector3(movementLeft.x,movementLeft.y,0);
      }
      }
      else if (Input.GetKeyUp(KeyCode.RightArrow))
      {
      Vector2 movementRight = new Vector2(1, 0);
      RaycastHit2D hitRight = Physics2D.Raycast(transform.position, movementRight, 1);

      if (hitRight.collider && hitRight.collider.gameObject.tag == "barrier")
      {
      Debug.Log("N/A");
      }
      else
      {
      player.transform.position += new Vector3(movementRight.x, movementRight.y, 0);
      }
      }
      else if (Input.GetKeyUp(KeyCode.DownArrow))
      {
      Vector2 movementDown = new Vector2(0, -1);
      RaycastHit2D hitDown = Physics2D.Raycast(transform.position, movementDown, -1);

      if (hitDown.collider && hitDown.collider.gameObject.tag == "barrier")
      {
      Debug.Log("N/A");
      }
      else
      {
      player.transform.position += new Vector3(movementDown.x, movementDown.y, 0);
      }
      }
      else if (Input.GetKeyUp(KeyCode.UpArrow))
      {
      Vector2 movementUp = new Vector2(0, 1);
      RaycastHit2D hitUp = Physics2D.Raycast(transform.position, movementUp, 1);

      if (hitUp.collider && hitUp.collider.gameObject.tag == "barrier")
      {
      Debug.Log("N/A");
      }
      else
      {
      player.transform.position += new Vector3(movementUp.x, movementUp.y, 0);
      }
      }
      else
      {
      Debug.Log("N/A");
      }






      unity3d collision-detection collider






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 at 5:24

























      asked Nov 16 at 2:26









      Kat K

      325




      325
























          1 Answer
          1






          active

          oldest

          votes


















          0














          A more simpler solution would be to use Physics.Raycast2D to check if theres any block in the way of your movement before moving it.



          This is rough idea of the code:



          // Some code to get input and end up with a movement vector
          ...
          movement = new Vector2(1, 0);

          // Raycast in the direction of movement with a distance of 1.
          RaycastHit2D hit = Physics2D.Raycast(transform.position, movement, 1);

          // We hit something and its a barrier
          if (hit.collider && hit.collider.gameobject.tag == "barrier")
          {
          // Don't move, play sound that indicate you hit a barrier or some sort
          }
          else
          {
          // Move to the new position
          transform.position += new Vector3(movement.x, movement.y, 0);
          }





          share|improve this answer























          • It seems to be throwing an error at the 'gameobject' in 'hit.gameobject.tag'. I have tried both versions of gameobject (GameObject and gameObject) but it doesn't like either of those.
            – Kat K
            Nov 16 at 3:24










          • I've updated the answer. Try hit.collider.gameObject.tag
            – SwiftingDuster
            Nov 16 at 3:42










          • now I'm getting an error on 'player.transform.position += movement'. I tried taking out the 'player.', and it was still unhappy. I've also tried '(Vector2)player.transform.position', but that didn't work either.
            – Kat K
            Nov 16 at 3:54










          • My bad. That's because its trying to add a Vector2 and Vector3 together.
            – SwiftingDuster
            Nov 16 at 3:58












          • I'm not getting any more errors, but the boxes are still clipping through the boundaries. I posted what my current code looks like up in the ask, if you don't mind taking a look?
            – Kat K
            Nov 16 at 5:25











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330583%2fdetect-collisions-with-three-objects%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          A more simpler solution would be to use Physics.Raycast2D to check if theres any block in the way of your movement before moving it.



          This is rough idea of the code:



          // Some code to get input and end up with a movement vector
          ...
          movement = new Vector2(1, 0);

          // Raycast in the direction of movement with a distance of 1.
          RaycastHit2D hit = Physics2D.Raycast(transform.position, movement, 1);

          // We hit something and its a barrier
          if (hit.collider && hit.collider.gameobject.tag == "barrier")
          {
          // Don't move, play sound that indicate you hit a barrier or some sort
          }
          else
          {
          // Move to the new position
          transform.position += new Vector3(movement.x, movement.y, 0);
          }





          share|improve this answer























          • It seems to be throwing an error at the 'gameobject' in 'hit.gameobject.tag'. I have tried both versions of gameobject (GameObject and gameObject) but it doesn't like either of those.
            – Kat K
            Nov 16 at 3:24










          • I've updated the answer. Try hit.collider.gameObject.tag
            – SwiftingDuster
            Nov 16 at 3:42










          • now I'm getting an error on 'player.transform.position += movement'. I tried taking out the 'player.', and it was still unhappy. I've also tried '(Vector2)player.transform.position', but that didn't work either.
            – Kat K
            Nov 16 at 3:54










          • My bad. That's because its trying to add a Vector2 and Vector3 together.
            – SwiftingDuster
            Nov 16 at 3:58












          • I'm not getting any more errors, but the boxes are still clipping through the boundaries. I posted what my current code looks like up in the ask, if you don't mind taking a look?
            – Kat K
            Nov 16 at 5:25
















          0














          A more simpler solution would be to use Physics.Raycast2D to check if theres any block in the way of your movement before moving it.



          This is rough idea of the code:



          // Some code to get input and end up with a movement vector
          ...
          movement = new Vector2(1, 0);

          // Raycast in the direction of movement with a distance of 1.
          RaycastHit2D hit = Physics2D.Raycast(transform.position, movement, 1);

          // We hit something and its a barrier
          if (hit.collider && hit.collider.gameobject.tag == "barrier")
          {
          // Don't move, play sound that indicate you hit a barrier or some sort
          }
          else
          {
          // Move to the new position
          transform.position += new Vector3(movement.x, movement.y, 0);
          }





          share|improve this answer























          • It seems to be throwing an error at the 'gameobject' in 'hit.gameobject.tag'. I have tried both versions of gameobject (GameObject and gameObject) but it doesn't like either of those.
            – Kat K
            Nov 16 at 3:24










          • I've updated the answer. Try hit.collider.gameObject.tag
            – SwiftingDuster
            Nov 16 at 3:42










          • now I'm getting an error on 'player.transform.position += movement'. I tried taking out the 'player.', and it was still unhappy. I've also tried '(Vector2)player.transform.position', but that didn't work either.
            – Kat K
            Nov 16 at 3:54










          • My bad. That's because its trying to add a Vector2 and Vector3 together.
            – SwiftingDuster
            Nov 16 at 3:58












          • I'm not getting any more errors, but the boxes are still clipping through the boundaries. I posted what my current code looks like up in the ask, if you don't mind taking a look?
            – Kat K
            Nov 16 at 5:25














          0












          0








          0






          A more simpler solution would be to use Physics.Raycast2D to check if theres any block in the way of your movement before moving it.



          This is rough idea of the code:



          // Some code to get input and end up with a movement vector
          ...
          movement = new Vector2(1, 0);

          // Raycast in the direction of movement with a distance of 1.
          RaycastHit2D hit = Physics2D.Raycast(transform.position, movement, 1);

          // We hit something and its a barrier
          if (hit.collider && hit.collider.gameobject.tag == "barrier")
          {
          // Don't move, play sound that indicate you hit a barrier or some sort
          }
          else
          {
          // Move to the new position
          transform.position += new Vector3(movement.x, movement.y, 0);
          }





          share|improve this answer














          A more simpler solution would be to use Physics.Raycast2D to check if theres any block in the way of your movement before moving it.



          This is rough idea of the code:



          // Some code to get input and end up with a movement vector
          ...
          movement = new Vector2(1, 0);

          // Raycast in the direction of movement with a distance of 1.
          RaycastHit2D hit = Physics2D.Raycast(transform.position, movement, 1);

          // We hit something and its a barrier
          if (hit.collider && hit.collider.gameobject.tag == "barrier")
          {
          // Don't move, play sound that indicate you hit a barrier or some sort
          }
          else
          {
          // Move to the new position
          transform.position += new Vector3(movement.x, movement.y, 0);
          }






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 16 at 3:57

























          answered Nov 16 at 3:05









          SwiftingDuster

          847315




          847315












          • It seems to be throwing an error at the 'gameobject' in 'hit.gameobject.tag'. I have tried both versions of gameobject (GameObject and gameObject) but it doesn't like either of those.
            – Kat K
            Nov 16 at 3:24










          • I've updated the answer. Try hit.collider.gameObject.tag
            – SwiftingDuster
            Nov 16 at 3:42










          • now I'm getting an error on 'player.transform.position += movement'. I tried taking out the 'player.', and it was still unhappy. I've also tried '(Vector2)player.transform.position', but that didn't work either.
            – Kat K
            Nov 16 at 3:54










          • My bad. That's because its trying to add a Vector2 and Vector3 together.
            – SwiftingDuster
            Nov 16 at 3:58












          • I'm not getting any more errors, but the boxes are still clipping through the boundaries. I posted what my current code looks like up in the ask, if you don't mind taking a look?
            – Kat K
            Nov 16 at 5:25


















          • It seems to be throwing an error at the 'gameobject' in 'hit.gameobject.tag'. I have tried both versions of gameobject (GameObject and gameObject) but it doesn't like either of those.
            – Kat K
            Nov 16 at 3:24










          • I've updated the answer. Try hit.collider.gameObject.tag
            – SwiftingDuster
            Nov 16 at 3:42










          • now I'm getting an error on 'player.transform.position += movement'. I tried taking out the 'player.', and it was still unhappy. I've also tried '(Vector2)player.transform.position', but that didn't work either.
            – Kat K
            Nov 16 at 3:54










          • My bad. That's because its trying to add a Vector2 and Vector3 together.
            – SwiftingDuster
            Nov 16 at 3:58












          • I'm not getting any more errors, but the boxes are still clipping through the boundaries. I posted what my current code looks like up in the ask, if you don't mind taking a look?
            – Kat K
            Nov 16 at 5:25
















          It seems to be throwing an error at the 'gameobject' in 'hit.gameobject.tag'. I have tried both versions of gameobject (GameObject and gameObject) but it doesn't like either of those.
          – Kat K
          Nov 16 at 3:24




          It seems to be throwing an error at the 'gameobject' in 'hit.gameobject.tag'. I have tried both versions of gameobject (GameObject and gameObject) but it doesn't like either of those.
          – Kat K
          Nov 16 at 3:24












          I've updated the answer. Try hit.collider.gameObject.tag
          – SwiftingDuster
          Nov 16 at 3:42




          I've updated the answer. Try hit.collider.gameObject.tag
          – SwiftingDuster
          Nov 16 at 3:42












          now I'm getting an error on 'player.transform.position += movement'. I tried taking out the 'player.', and it was still unhappy. I've also tried '(Vector2)player.transform.position', but that didn't work either.
          – Kat K
          Nov 16 at 3:54




          now I'm getting an error on 'player.transform.position += movement'. I tried taking out the 'player.', and it was still unhappy. I've also tried '(Vector2)player.transform.position', but that didn't work either.
          – Kat K
          Nov 16 at 3:54












          My bad. That's because its trying to add a Vector2 and Vector3 together.
          – SwiftingDuster
          Nov 16 at 3:58






          My bad. That's because its trying to add a Vector2 and Vector3 together.
          – SwiftingDuster
          Nov 16 at 3:58














          I'm not getting any more errors, but the boxes are still clipping through the boundaries. I posted what my current code looks like up in the ask, if you don't mind taking a look?
          – Kat K
          Nov 16 at 5:25




          I'm not getting any more errors, but the boxes are still clipping through the boundaries. I posted what my current code looks like up in the ask, if you don't mind taking a look?
          – Kat K
          Nov 16 at 5:25


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53330583%2fdetect-collisions-with-three-objects%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to send String Array data to Server using php in android

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Is anime1.com a legal site for watching anime?