Search Unity

Hitbox bug

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

  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 how to fix this?
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    Can you show the code on the car or the object with the collider? It is hard to decipher why without seeing the code.
     
  3. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    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.     }
     
  4. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    Hmm, doesnt appear to be anything with the collider on this script. Are there any other scripts that reference the Collider2D or the Car's sprite size? Also, do the car's colliders immediately grow in size when you start the game or is it after collisions or something?
     
  5. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
    it's right when i start the game
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,481
  7. FireJojoBoy

    FireJojoBoy

    Joined:
    Oct 30, 2019
    Posts:
    65
  8. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    None of the code you showed has anything changing the size of colliders or the gameobjects. At this point I would just recreate your gameobject and code and see if it gets fixed. It isnt ideal but has helped me in the past. And, you dont have too much code where it would take longer than 15 minutes.
     
    FireJojoBoy likes this.
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,481
    FYI: It was sorted in the other thread and was related to some other collider.
     
    FireJojoBoy and Cornysam like this.