Search Unity

Collider too big

Discussion in '2D' started by FireJojoBoy, Jan 15, 2020.

Thread Status:
Not open for further replies.
  1. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    i have a racing game where you can collide with other cars.
    i made the collider way smaller than the cars but when i play the ame it's like 5 times bigger than the car
    can annybody help me fixing this?
    is it a bug from unity?

    here's the code of the Player:

    Code (CSharp):
    1.     public void OnTriggerEnter2D(Collider2D other)
    2.         {
    3.             if (other.tag == "SlipperyEnd")
    4.             {
    5.                 slippery = false;
    6.             }
    7.    
    8.             if (other.tag == "SlipperyActivate")
    9.             {
    10.                 slippery = true;
    11.             }
    12.    
    13.             if (other.tag == "OtherCar")
    14.             {
    15.                 Collide();
    16.             }
    17.         }
    18.    
    19.         public void Collide()
    20.         {
    21.             HowFast = 0;
    22.             normalSpeed = 1f;
    23.         }
    24.  
    edit: OMG I DETATCHED THE TUNNEL LIGHT COLLIDER AND IT WORKS NOW
     
    Last edited: Jan 19, 2020
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    When you run the game, the collider becomes much bigger, and stays like that?

    Is this just on the player object, or does it happen on all cars?

    There's nothing in this script to cause this, so it must be something else. Is this the only script on the player object?

    Can you take some screenshots that show your Heirarchy view (fully expand the player object if it has children) and your Inspector with the player object selected?
     
    FireJojoBoy likes this.
  3. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    there's no other script that uses the collider and no other object with an collider
    it's useless to show screenshots because you can't see the collider
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    You will see the collider if you have it selected or if you go into Project Settings > Physics 2D > Gizmos > Always show colliders.

    Colliders don't resize unless the collider geometry is explicitly changed via its properties or the Transform scale is changed so it's absolutely worth showing this visually. The gizmo will show you exactly how big the collider is and the fact that you say a screenshot won't show the collider makes me thing that maybe you're not away of how big it is.

    Of course I'm completely guessing but maybe check what the gizmo shows.
     
    FireJojoBoy likes this.
  5. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    thanks it's wierd that this option didnt work for me and yes, i don#t know how big it is but the car is colliding before it hitts the other car. i don't know what i should do
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    This option works perfectly fine so if you cannot see the collider then you must be doing something wrong. Simply selecting the GO with it on will display it. If you look in the "Scene" view, make sure the "Gizmos" button at the top has been selected as you can click on it to turn on/off all scene gizmos (ignoring the drop-down).

    Just add a GameObject, add a CircleCollider2D. If you don't see it then you've got gizmos turned off.
     
    FireJojoBoy likes this.
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
  8. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    thanks now i can see that the colliders are as small as they should be but if they are ok what am i doing wrong?
     
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    It should be clear that I have no way of telling you what is going wrong until you provide more info.

    At least post an image (preferably a video) of them suddenly getting bigger or confirm that the gizmo shows them getting bigger and it's not just the fact that you're seeing your code running too early or something.
     
    FireJojoBoy likes this.
  10. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    ähm.JPG
    if the cars are that mutch away they collide. the other collider in the picture has nothing to do with that and it's just making the street behind the player disappier
     
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    So you're saying that the colliders are not actually resizing but you're getting a callback from these two colliders that indicates that they're touching?

    Can you confirm that it is indeed these two catching and that you're not contacting another collider? One way is to delete the other collider in the callback (single step this in pause mode) and check that the collider on the other collider disappears. If not, it's some other collider you've not accounted for.

    If you can duplicate this in a simple scene and upload it somewhere, I'd be happy to take a quick look at it.
     
    FireJojoBoy likes this.
  12. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    yes they do this wierd stuff allways, also when they aren't tuching the other collider.
    in the script it's checking if the colliders tag is "OtherCar"
     
  13. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Are you sure you've not modified the 2D Physics Settings and done something like increase the Physics2D.defaultContactOffset ?

    You can reset those settings, noting any that you need changed such as gravity.

    Beyond that, there's no reason why this would happen at all and if it did, it'd be a serious bug and a heck of a lot of people would have their pitchforks out. ;)
     
    FireJojoBoy likes this.
  14. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    thanks. i did reset the settings and i checked if i changed the Physics2D.defaultContactOffset seems like i need to report this bug
     
  15. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    How do you know this is a bug in Unity? If colliders reacted like this then users would be up in arms.

    Can you create a new project and get two such colliders to come in contact from so far away? If you can then please go ahead and report a bug and provide me with the case number as I'd happily take a look at it.
     
    FireJojoBoy likes this.
  16. Wezai

    Wezai

    Joined:
    Dec 30, 2016
    Posts:
    74
    The cars look like they have an extra collider (the huge green square in your picture). Check the car object, its children or even its parent to see if anything else has a big one.
     
    FireJojoBoy likes this.
  17. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Now I'm confused. You said, "the other collider in the picture has nothing to do with that and it's just making the street behind the player disappier".

    Can you please show a better view and identify what is what?

    Also, I said this and perhaps you should try it, "One way is to delete the other collider in the callback (single step this in pause mode) and check that the collider on the other collider disappears. If not, it's some other collider you've not accounted for."
     
    FireJojoBoy likes this.
  18. Wezai

    Wezai

    Joined:
    Dec 30, 2016
    Posts:
    74
    My bad, I didn't see that in the post above.

    Still, this is such a simple scene that the only thing I can think of is that they might be the culprit. Your advice is still the best approach.
     
  19. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    no they dont, here's the prefab:
    oof.JPG
     
  20. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    Here is everything you see explained:

    explain.JPG

    edit: OMG I DETATCHED THE TUNNEL LIGHT COLLIDER AND IT WORKS NOW
    thank you so mutch i mean you said that i should remove other colliders in the car
    thank you :D :D :D :D
     
    Last edited: Jan 19, 2020
    MelvMay likes this.
  21. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Actually it was my bad, I read your post as if @FJB_creator wrote it! Got confused. :)

    Well there's no reason they'd hit at such distances and honestly I don't know what to suggest but really, no bug is going to allow collisions from such distances. It'd effectively make 2D physics useless and we would've had a lot of bug reports.

    I'll ask for the final time if you can try deleting the other collider on the callback and/or hosting a simple reproduction project so I can take a look. Failing that, I'm not sure how I can help further.
     
    FireJojoBoy likes this.
  22. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Good to hear you got it working. :)
     
    FireJojoBoy likes this.
  23. ItsBehradaYt12

    ItsBehradaYt12

    Joined:
    Feb 14, 2024
    Posts:
    3
    Yeah i have a similiar problem but i have checked every single pixel on the entire project nothing
     
  24. ItsBehradaYt12

    ItsBehradaYt12

    Joined:
    Feb 14, 2024
    Posts:
    3
    Does it have anything to do with Tags ( i use collider.CompareTag)
     
  25. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Please don't necropost. Use your own threads when you have a problem.

    Thanks.
     
Thread Status:
Not open for further replies.