Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Bug Instantiated Bullet(IsTrigger + Box Collider) Is Not Colliding With Other Colliders

Discussion in 'Scripting' started by dakspieth, May 25, 2024.

  1. dakspieth

    dakspieth

    Joined:
    Jan 7, 2023
    Posts:
    3
    Keep in mind I am still pretty new to Unity. The enemy instantiates the bullets at the player, but the bullet goes through walls and I am trying to fix it. It has been a few days and I can't find a solution anywhere. The bullet has a box collider set to istrigger and the level is made up of a bunch of convex mesh colliders, which I have heard interact with triggers. Both the bullet and level have rigidbodies. Please ask for any more info if needed.

    This code is attached to the bullet and the level is set to tag "Wall"
    I have more code in the function but it is not relevant.
    Code (CSharp):
    1. public void OnTriggerEnter(Collider other)
    2.     {
    3.          if (other.gameObject.tag == "Wall")
    4.         {
    5.             Debug.Log("col");
    6.  
    7.             Destroy(gameObject);
    8.         }
    9.     }
    Any help is greatly appreciated.
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,687
    What's the code you're using to move them?
     
  3. dakspieth

    dakspieth

    Joined:
    Jan 7, 2023
    Posts:
    3
    Code (CSharp):
    1.     public float bulletSpeed;
    2.  
    3.  
    4. void Start()
    5.     {
    6.         rb.AddForce(transform.forward * bulletSpeed, ForceMode.Impulse);
    7.  
    8.     }
    This is in the same script as before.
     
  4. dakspieth

    dakspieth

    Joined:
    Jan 7, 2023
    Posts:
    3
    Umm... so I think I got it working. The problem was that the rigidbody I reference came from the prefab and not the instantiated bullet.

    Sorry for taking your time... :oops: