• 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 testinapuzz · Nov 19, 2020 at 12:47 PM · 2d2d gamebug2d-physics2d collision

2D collision matrix does not work in unity 2020

I am trying to make a system where when the player pushes on button he changes layer from "Player layer" to an "invicible layer" where the player can't collide with enemy or other objects. so i created the "enemy" and "the invicible" layers and disabled the collision between the two from the 2d collision matrix but the collision still happens. i tried to set the player to the invicible layerfrom the start to make sure there wasn't a problem with changing layers with the script but the collision probblem still persisted. I tried using various functions like Physics2D.IgnoreLayerCollision(10,11, true) and Physics2D.IgnoreCollision(enemy.GetComponent(), player.GetComponent()); but not$$anonymous$$ng changed. To better understand the problem i tried disabling (i tried with all the methods above) the collision between player and an object in the scene (because i have more control on the player movement) and i saw that the collision still happens when i move horizontally but if jump on the object the player ignores the collision for a split second but then gets glitched "inside" the object. All of t$$anonymous$$s problems exist only in unity 2020, not in 2019 but i can't use the 2019 version because i need to import some packages that are available only in the 2020 version.

At t$$anonymous$$s point i just don't know what to do and i am quite desperate, any help would be much appriciated

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by sztobar · Nov 19, 2020 at 01:25 PM

  1. How do you detect a collision? Do you use Physics.Raycast(), collider.Cast() or anyt$$anonymous$$ng like that, or do you detect it using OnCollisionEnter2D or OnTriggerEnter2D method call?

  2. Do the player and button have both rigidbody2d attached?

  3. Are any of the colliders have isTrigger flag enabled on it?

  4. Do you have in code any calls to IgnoreLayerCollision(10, 11, false) or anyt$$anonymous$$ng that can potentially enable collision between those two?

Comment
Add comment · Show 3 · 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 testinapuzz · Nov 19, 2020 at 09:24 PM 0
Share

1 when i say the collision still happens i mean that the player still behaves like it's colliding with the box collider

2 yes they have rigidbody2d attached

3 no, none of the colliders is set to trigger

4 the IgnoreLayerCollision(10, 11, false) is called in an update method in a script attached to the player, i also tried calling it from both start and awake but nothing changed.

Also, thanks for trying to help, i hope to solve this problem asap

avatar image sztobar testinapuzz · Nov 20, 2020 at 10:21 AM 0
Share

I'm not sure if you made a typo, or mistaken an argument. Notice that: When you call IgnoreLayerCollision(10, 11, false) you enable collision between the layers. When you call IgnoreLayerCollision(10, 11, true) you disable collision between the layers.

You wrote that IgnoreLayerCollision(10, 11, false) is called in an update of the player. So you enable the collision on every frame.

avatar image testinapuzz sztobar · Nov 20, 2020 at 05:02 PM 0
Share

Ah, sorry it was a typo, i checked in the script is setting it to true

avatar image
2

Answer by Vishal0703 · Mar 22, 2021 at 11:25 AM

Are you sure you disabled the collision in Physics2D collision matrix and not in the Physics Collision matrix??? (I am assuming you are working on a 2D game here)... Was just having t$$anonymous$$s issue and seems like I was disabling the collision in Physics collision... Disabling the same collision in Physics2D worked for me...

Comment
Add comment · 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
1

Answer by SteveHoward · Nov 19, 2020 at 01:52 PM

@testinapuzz I don't see the same problem in 2020.1. I created an obstacle in my game and set the layer to "test". I don't get a collision. Here is my collision matrix. Turning off collisions between test and Player. I didn't do the invincible layer but you said even if you change the layer to invincible it doesn't work.

[1]: /storage/temp/171260-project-settings-and-level1.png


project-settings-and-level1.png (30.9 kB)
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 testinapuzz · Nov 19, 2020 at 09:15 PM 0
Share

i did the same thing but on my project doesn't work, maybe i will try reinstalling unity

avatar image
0

Answer by atorstling · Aug 06, 2021 at 03:07 PM

I thought I had ran into t$$anonymous$$s bug, but it turned out that I had enabled the "Use Collider Mask" option in a "Platform Effector 2D", w$$anonymous$$ch effectively overrode w$$anonymous$$ch layers t$$anonymous$$s platform would collide with. That meant that it could create collisions between layers w$$anonymous$$ch weren't colliding according to the matrix. Bit of a facepalm, but yeah...

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

346 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 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 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 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

Death Counter dont work when changing scenes 2 Answers

Why Is there A slight jitteryness on player movement and camera? 0 Answers

2D Detect collisions of a 2D block only on left/right (not top/bottom) 0 Answers

Use 2D Effectors with Raycast Collision Method 0 Answers

Why does BoxCollider2D distance depend on distance to camera center? 0 Answers


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