Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by EZS · Sep 27, 2018 at 11:30 PM · 2d-physicscollision2dignore collisions

2D Collision Matrix Not Working

Hello everyone!

So I'm currently working on a 2D top down shooter project where the player is supposed to remain within the confines of the map, but the enemies can go through the boundaries. My problem is that my attempts to ignore collisions between the 2D physics layers "Enemies" and "Bounds" have proven quite unsuccessful. I have double, triple, and quadruple checked the collision matrix in the physics 2D settings to make sure I did it right, and I'm 99.99% sure that I did it correctly. I even tried to call the Physics2D.IgnoreLayerCollision( 9 , 10 , true ); function, but to no avail. Any and all help would be appreciated!

Thanks collective!

-ezshack

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by KittenSnipes · Sep 27, 2018 at 11:42 PM

@EZS So I would do this instead:

 public GameObject enemy;
 public GameObject barrier;
 
 void Start() {
     Debug.LogError("Layer Of Enemies: " + enemy.layer);
     Debug.LogError("Layer Of The Barriers: " + barrier.layer);
     Physics2D.IgnoreLayerCollision(enemy.layer, barrier.layer, true);
 }

This method usually guarantees you have the right layer and you only need one of each of the game object's. Oh and for debugging I would also keep the Debug.Log messages so you can check and see if your layers were correct. Hope this helps you fix it.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image EZS · Sep 28, 2018 at 02:00 PM 0
Share

Would it be helpful to know that I'm using enemy prefabs?

avatar image KittenSnipes EZS · Sep 29, 2018 at 01:00 AM 0
Share

@EZS

Well then you just need to get a reference towards the enemy that is spawned.

avatar image
0

Answer by EZS · Oct 01, 2018 at 05:10 PM

@KittenSnipes Thank you for your help, it did end up helping me get where I was intending to go.

So I ended up solving the problem myself. After receiving very limited help on Unity Answers or Reddit, I eventually fiddled around enough that I got where I needed to be. I ended up needing to set the physics2d layers manually in my code then using the values I set them to in the IgnoreLayerCollision() function. I think that there is a bug with Unity's 2D physics layers. Does anyone think I should submit a bug report?

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nicmarxp · Jan 30, 2019 at 10:01 PM 0
Share

Very interesting. I'm making something similar and have three layers, Player, Projectile and Spaceobj. All 3 are supposed to collide according to the matrix, but the player doesn't react to Projectiles. However when I change the layer of Player to Spaceobj, it works. So it feels like the matrix is buggy somehow, but I might be missing something, as I'm basing my work on the $$anonymous$$ore$$anonymous$$ountains Topdownengine.

The Physics2D.IgnoreLayerCollision command changed the $$anonymous$$atrix, but not the effect of it. So what did you actually do?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

94 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Using OnTriggerEnter2D/OnTriggerExit2D with Time.timeScale set to 0 1 Answer

Collision stops working at certain situations. Help? 1 Answer

How to use contact data from simultaneous collisions? 3 Answers

Different platform effector 2d rotations for different colliders 1 Answer

how to make a 2d colider script detector,how mto make a simple colision detect2d script 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges