Quantcast
Channel: Questions in topic: "ignorecollision"
Viewing all articles
Browse latest Browse all 148

IgnoreLayerCollision not working

$
0
0
I have a bullet spread code which spawns 5 projectiles in the same position. In order to prevent the projectiles from colliding with each other, I used ```Physics.IgnoreLayerCollision```. The bullets are set to their own layer, and I called the function in the ```Start()```, like so: public LayerMask bullet; void Start() { Physics.IgnoreLayerCollision(bullet, bullet); Debug.Log("Collision ignored"); } I did not make a mistake with the variables. They're all set up correctly, and the ```Debug.Log``` message actually showed. ---------- The thing is, this actually worked fine when done in my test script, but did not work at all when I moved this to my actual shooting script (Again, no variables were mistaken, everything was set up the way they're supposed to). Until I tried to modify the shooting of my test script, which made it not work at all for it (for some weird reason). For extra measures, I also checked if the collision object is in the bullet layer for the projectiles: void OnCollisionEnter(Collision other) { if (other.gameObject.layer == bulletLayer) { return; } GameObject effect = Instantiate(particle, transform.position, Quaternion.LookRotation(surfaceNormal)); effect.transform.parent = other.transform; Destroy(effect, particleTime); Destroy(gameObject); Debug.Log("Bullet destroyed"); } And yet, it showed the ```Debug``` message 5 times (once for each bullet). ---------- This is really getting on my nerves, and any help of any kind would be very much appreciated.

Viewing all articles
Browse latest Browse all 148

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>