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 /
This question was closed Oct 15, 2015 at 08:00 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Leggy7 · Oct 11, 2015 at 03:08 PM · raycastphysics2dlayermask

Why is Raycast hitting masked layer?

Many questions have been posted on this topic but I'm facing a weird behavior which I could not find an explaination for.

I perform a raycast giving it a LayerMask parameter which is defined as public variable and set in the inspector with thick on layer "Wall" and "Enemy".

At first glance it appeared to work fine because raycast rightly stops on GameObjects with that layer.

But then I saw that it stopped also on GameObjects with default layer, like if the LayerMask was ignored. Is there something I'm missing?

According to this answer I set up everything correctly and I expected it to work fine.

Looking at the inspector at Runtime I can clearly see that my mask is set only to "Wall" and "Enemy", and that the GameObject the collider is attached to has default layer set. I'm then stating that the mask the way I'm using it does not exclude other layers. The only way I found to have this working is by setting that GameObject layer to Ignore Raycast but in this case the LayerMask is not necessary.

I'm calling the function this way:

 RaycastHit2D inSight = Physics2D.Raycast(start, end, lm); 

Maybe is there something different using Physics2D?
I would really enjoy touse LayerMasks instead of giving specifically Ignore Raycast to whatever I want to ignore. Any clue?

Comment
Add comment · Show 1
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 Leggy7 · Oct 15, 2015 at 08:18 PM 0
Share

@meat5000 may you reopen the question? I accepted an answer that was not correct

1 Reply

  • Sort: 
avatar image
-1

Answer by MadDevil · Oct 13, 2015 at 06:05 AM

@Leggy7

giving a layer, while raycasting means that that raycast will return any info if it hits the objects of that layer. but i can collide with every layer.

if you want that you can use ignoreraycast layer.

http://docs.unity3d.com/Manual/Layers.html

Comment
Add comment · Show 4 · 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 Leggy7 · Oct 13, 2015 at 11:29 AM 0
Share

So, you are saying that to have a raycast pass throughout a collider then only thing i can do is use RaycastAll() or use ignore raycast layer? And then, Layer$$anonymous$$asks does not serve for this purpose? This would be WOW!

avatar image meat5000 ♦ Leggy7 · Oct 13, 2015 at 02:14 PM 0
Share

Invert your layermask to avoid a layer. It will hit all other layers.

avatar image MadDevil Leggy7 · Oct 14, 2015 at 04:21 AM 0
Share

@Leggy7

Layermask is used when you want only some objects to return the hitinfo not all in the scene. you can sort out objects with help of layermask.

avatar image Leggy7 MadDevil · Oct 14, 2015 at 01:26 PM 0
Share

@$$anonymous$$adDevil So if my need is to reach a certain layer passing THGOUGHOUT other layers I'm right in saying that I need to use raycastAll or set layers to be ignored to "ignore raycast"?

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why is RaycastHit2d Not working 0 Answers

2D Raycast Layer Mask not working 1 Answer

Bitmask/LayerMask used in raycast not working 2 Answers

Raycast and Layer Masks 1 Answer

Physics 2d raycaster from EventSystems for overlapped colliders 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