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 christianjulch · Apr 20, 2016 at 04:49 AM · playerraycastinglayers

How to allow a ray-cast through a player?

I am creating an item pick up script, and the main purpose for it is to check the tag and info on another script attached to a game object or the item. What is happening to the ray though is it is passing through the player, my question is how do i allow a raycast through the player object?

Thank you ahead of time.

-Christian J

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 Cherno · Apr 20, 2016 at 10:35 AM 0
Share

Do what Johat suggested, or use RaycastAll and iterate through the hit colliders until you've found the one you need.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Johat · Apr 20, 2016 at 06:40 AM

The simplest way to achieve this would probably be through a LayerMask. See the Physics.Raycast reference here.

If you put the player on a different layer to the GameObjects you want to check against, then you can mask that out to ignore it.

I would have a field in your script of type LayerMask since this will give you a nice drop-down in the inspector -- you can choose multiple layers to ignore easily if you like.

Something like:

 public LayerMask IgnoreLayers;

Then your raycast could be something like this (check the reference for the version of raycast you want to call):

 // Bitwise not -- ~ -- flips all the bits of the integer in this case, to allow every layer EXCEPT those you selected in the LayerMask
 Physics.Raycast(someOrigin, someDirection, someMaxDistance, ~IgnoreLayers.value);

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.

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

NavMeshAgent Not Working? 1 Answer

Can i add texture to multiple layers of player? and how? 0 Answers

Raycast to OVRplayercontroller,Raycast to OVRplayercontroller - bugged 1 Answer

How do i make my own ignore raycast user layer? 1 Answer

Raycast Not Drawing In Target Direction? 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