Search Unity

Unity 2d Box Collider Not Working

Discussion in '2D' started by fleap3, Dec 7, 2013.

  1. fleap3

    fleap3

    Joined:
    Dec 7, 2013
    Posts:
    5
    I have tryed to figure this out but I found nothing, I have 2 sprites same x cordinate and when the y and z meet They Pass through each other. I have the 2D box colliders checked off. Thanks For Reading This! Hope U Know How To Help :)
     
    Last edited: Dec 10, 2013
  2. Maklaud

    Maklaud

    Joined:
    Apr 2, 2013
    Posts:
    551
    Please Don't Start Each Word From The Capital Letter - it's difficult to read :)

    As for the problem, try to add RigidBody2D. I have colliding objects, both have Box Colliders 2D with "Is Trigger" turned on and Rigid Bodies 2D with "Gravity Scale" == 0 (so as not to let them fall).
     
  3. fleap3

    fleap3

    Joined:
    Dec 7, 2013
    Posts:
    5
    Thanks for helping me with that Caps Thing (i edited it and fixed it). Sorry I am 10 and new to Unity so I'm still learning :).

    I tried that and it isn't working. My project can be found here(Link: https://www.dropbox.com/s/v7papg7u4z9z65u/firstgame.zip), could you look at it and tell me why the collision detection isn't working? WASD to move (if needed TFGH for creeper move)
     
    CliffracerX likes this.
  4. softwizz

    softwizz

    Joined:
    Mar 12, 2011
    Posts:
    793
    For starters you are using Vector2 so there is no Z-axis anyway.

    I am assuming you are using the latest version of unity at this point in time and are using the 2D system so set the game up for 2D by using an orthographic camera and click the '2D' button in the scene tab.

    You dont need to put ; at the end of the closing } in 'creeper following algorithm.js'

    You dont need any transform.position.z really as you are not using them.

    This should never be true if you want to detect the collision as the colliders should stop this happening:
    Code (csharp):
    1. if (cx == sx  cy == sy)
    2.  {
    3. transform.Translate(Vector2(1, 0) * Time.deltaTime * speed);
    4. }
    There are some other things so I made a package of the changes I made.
    Make sure the main camera is set to:

    position x0 y0 z-10
    projection orthographic
    size 12
    clipping planes near 0.3 far20

    View attachment $first_project.unitypackage