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
3
Question by Bob-The-Zealot · Apr 02, 2015 at 03:02 AM · raycasttrigger

Raycast hits trigger

How can I prevent a raycast from detecting a trigger?

I'm simply checking if the raycast hit's anything.

 forwards = Physics.Raycast (transform.position, -transform.forward, 0.5f);

Btw, most of the time I'm inside a big trigger, and it's colliding against the edge of the trigger from the inside.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Bob-The-Zealot · Apr 02, 2015 at 03:20 AM

Do this:

Go to: Edit -> Project Settings -> Physics -> Raycasts Hit Trigger

And set that to false.

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 CowNecromancer · Apr 20, 2015 at 12:12 AM 0
Share

lol, answer your own question

avatar image Kiwasi · Apr 20, 2015 at 12:26 AM 2
Share

Answering your own question is considered polite and correct if you locate the answer before the community does.

Thumbs up.

avatar image Bob-The-Zealot · Apr 29, 2015 at 03:11 AM 0
Share

Thanks!​​​

avatar image
3

Answer by ian_sorbello · Apr 02, 2015 at 03:13 AM

You need to filter using layers. Your trigger collider needs to be assigned to a layer that your raycast won't flag as a hit.

To do this use

http://docs.unity3d.com/ScriptReference/Physics.IgnoreLayerCollision.html

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
0

Answer by Ebonicus · Dec 14, 2016 at 09:57 AM

Thank you for this post, I don't understand why by default a raycast would hit a trigger in Unity. Raycast is a linear sensor and a collider set to trigger/true is a volumetric sensor, sensors should never detect other sensors by default. That's like a laser pointer setting off a landmine.

It took me too long to figure out it was even a raycast causing my issue, I originally thought the trigger checkbox was bugged. You have brought me peace.

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 Unplug · Feb 19, 2018 at 01:14 AM 1
Share

it's a old thread, but seeking myself more info about it land me here so i'll answer Ebonicus question about why would a trigger be hit.

I'll give you an easy example. I'm my scene, I see camera raycast to detect certain object and area. I have a door peeking mechanism and in order to peak the door, you look at the edge. The edge zone is a trigger collider. The raycast need to hit it, but i don't want the player to hit it. I can imagine dozen of exemple where a "zone" is require for certain action that rely on raycast whitout the need of a collider.

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

23 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

Related Questions

How can i make only some Raycasts hit triggers 1 Answer

Trigger and raycast error? 2 Answers

Can't click gameobject when over another trigger? 1 Answer

Using raycasts and triggers 1 Answer

Is it possible to check how much a trigger is filled by %? 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