- Home /
Complex collision layers
Hello, I am working on a 2D game with vehicles. I have made sort of a tank hull with a tracks system: What I want to do is to lower the hull slightly, so it partially behind the tracks and the whole machine isn't that high. For this I need to use two collision groups, for the hull and for the tracks to prevent them from colliding with eachother. The problem is, however, that I will have other machines and I want the tracks of this machine to collide with their hulls, but not with it's own hull and that would (I guess) require additional 2 layers for each machine which isn't effective at all and AFAIK it's impossible to add new collision layers while the game is running. I have found in the Unity Manual that there is a Physics2D.IgnoreCollision() function that disables collision between two colliders. But my tracks consist of 31 collider, the hull consists of 16 and there's also 7 wheels. Running the function for each collider pair, on each spawned machine would hit the performance heavily.
Is there a simpler way to make these collider groups ignore eachother in the way specified above?
Answer by Bunny83 · Jan 19, 2018 at 02:55 AM
I would recommend to use seperate colliders. So use your tracks colliders to collide with the world and just add another collider around the tracks for tank - tank collisions. So you would have those layers:
Tracks
Body
World
Allow collisions between Tracks and World and Body with Body. As i said you should have fix colliders on the Body layer that covers the whole tank.
Hmm, that should work if the tracks are always the same but what if a wheel can fall off or the track can break apart?
Your answer
Follow this Question
Related Questions
Collision point problem 1 Answer
OnCollisionEnter2D in a puzzle game with each block snapped to a grid? 1 Answer
Collision stops working at certain situations. Help? 1 Answer
After Collision Matrix change in runtime, effects not immediatly visible 1 Answer
How do I prevent multiple triggers using OnTriggerEnter? 1 Answer