Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 jvt619 · Dec 29, 2013 at 06:53 PM · raycastlayersignorethroughpass

Raycast still passes through even with layers!

 public LayerMask layerMask;

 void Update(){

    Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2, 0));
    RaycastHit hit;
    if (Physics.Raycast (ray, out hit, Mathf.Infinity, layerMask))
    {
       canUse = false;
       Destroy(LockerClone);
       LockerClone = Instantiate(Locker, hit.point, Quaternion.identity) as GameObject;
       alreadyGotColor = false;
    }

}

Even if there is a collider/wall infront of the player the raycast will still hit the object that has the layer mask on. Even if I put IgnoreRaycast on the walls it will still hit. This is an FPS game

alt text

Comment
Add comment · Show 6
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 robertbu · Dec 29, 2013 at 07:04 PM 0
Share

You need to explain more about the issue here. And how do you calculate the layer$$anonymous$$ask?

avatar image robertbu · Dec 29, 2013 at 07:20 PM 0
Share

So you problem is that the Raycast() is ignoring walls?

  • How are the walls constructed? Planes are one-sided for example.

  • What calculation do you do to set the layer mask?

  • How did you set the layers for the walls and the object?

  • What happens if you remove the 'layer$$anonymous$$ask' from your Raycast?

avatar image robertbu · Dec 29, 2013 at 07:26 PM 0
Share

A layer$$anonymous$$ask is usually used to restrict a raycast to specific layers. It does not mask out, it masks in. So is the layer your wall is on included in the mask you set in the inspector. So are the layer you have the walls set to included in the mask?

avatar image sparkzbarca · Dec 29, 2013 at 07:27 PM 0
Share

yea raycasts actually have by default a layermask which is ~2

~2 means to cast against everything but items in layer 2 (the default layer for ignore raycast)

avatar image jvt619 · Dec 29, 2013 at 07:34 PM 0
Share
  • All of the walls are cubes.

  • I calculate the layermask on the Inspector mode

  • Walls are on "Default" layers while the blue objects are "Targetable" layer("Targetable" is a layer$$anonymous$$ask)

  • It will hit everything.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

19 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

Related Questions

Ignoring Layer for OnMouseEnter/OnMouseExit 0 Answers

function OnMouseOver() ignore selected raycast 1 Answer

Can't Ignore a Layer when raycat 0 Answers

Ignoring an object (using raycast with layers) is not working 1 Answer

Shoot through walls 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