Search Unity

BoxCollider2D.offset/size breaks my collider.

Discussion in 'Scripting' started by AV_Corey, Oct 21, 2016.

  1. AV_Corey

    AV_Corey

    Joined:
    Jan 7, 2016
    Posts:
    122
    So I want the size and offset of the BoxCollider2D to change when the player crouches. I changed the BoxCollider2D in the editor to fit the crouching sprite and noted down the size/offset x and y values and then put them in my script as so:

    Code (CSharp):
    1. GetComponent<BoxCollider2D>().offset = new Vector2 (0.0002999306f, -0.2601998f);
    2. GetComponent<BoxCollider2D>().size = new Vector2(0.4f, 0.4596007f);
    Whenever I press the crouch button the BoxCollider2D breaks and it displays this message: 'The collider did not create any collision shapes as they all failed verification. This could be because they were deemed too small or the vertices were too close. Vertices can also become close under certain rotations or very small scaling'.

    Even if I change the size/offset x and y values to something simple like 1, they still break.
    Even if I change them to a value that they are already set as they break.

    What am I doing wrong?
     
  2. AV_Corey

    AV_Corey

    Joined:
    Jan 7, 2016
    Posts:
    122
    There was something wrong in another part of my code, I don't wanna talk about how simple the solution was lol.