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
13
Question by JBoy · Jul 05, 2012 at 12:29 AM · raycastcollidertrigger

raycast ignore trigger colliders?

Hi. I am currently working on an fps game. I have created some triggers for instantiating enemies and sound effects. I have also created a weapon script that uses raycast to instantiate bullet hole prefabs, knock rigidbodies over and send a damage message to the enemies. My triggers block the raycast message and instantiate a bullethole in mid-air if I shoot at them. How do i make the raycast completely ignore the trigger colliders?

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

5 Replies

· Add your reply
  • Sort: 
avatar image
92

Answer by Okido · Mar 04, 2014 at 01:41 AM

To have your raycasts ignore all trigger colliders in 5.2 and up, go to (still correct in Unity 2021):

Edit > Project Settings > Physics > Uncheck "Queries Hit Triggers"

(If you're using an older version of Unity, the check box is called "Raycasts Hit Triggers")

I know this is an old topic, but seeing as its the first result when googling the problem it should still be helpful.

Comment
Add comment · Show 9 · 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 superme2012 · Jan 21, 2015 at 02:55 PM 2
Share

Very handy if you got 2 colliders on one game object like I have.

avatar image bl4st · Feb 20, 2015 at 03:07 AM 1
Share

it helped !

avatar image Stitchey_ · Jul 07, 2015 at 01:24 PM 1
Share

You just saved my day. I have fire triggers and also coins in my 2D sidescroller, and I was trying to make a ray that checks if you can stand up after a crouch.

avatar image matthew2 · Feb 04, 2017 at 09:04 PM 1
Share

Do you know? Do you have any idea? DO YOU $$anonymous$$NOW HOW THAN$$anonymous$$FUL I A$$anonymous$$ FOR THIS ACTUALLY WOR$$anonymous$$ING?

Thanks.

avatar image Bill-Sansky · Oct 21, 2017 at 11:30 AM 1
Share

Supplying QueryTriggerInteraction.Ignore in the raycast call is a more flexible solution, like mentioned below by Anders$$anonymous$$almgren :)

Show more comments
avatar image
33

Answer by AndersMalmgren · Jun 07, 2017 at 01:41 PM

If you have alot of raycasting third party libraries it can be dangerous chaning the global setting like Okido suggest. Instead supply QueryTriggerInteraction.Ignore to the raycast method

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 Bill-Sansky · Oct 21, 2017 at 11:28 AM 1
Share

Thanks! This is much safer for sure

avatar image klesun · Mar 31, 2018 at 09:26 PM 3
Share

Usage example: var wasHit = Physics.Raycast (origin, direction, out result, maxDistance, -5, QueryTriggerInteraction.Ignore)

avatar image Bubsavvy · Aug 05, 2018 at 10:39 PM 0
Share

This should be the accepted answer. Have alot of issues with third parties and plugins in the past. Thanks for this.

avatar image
3

Answer by SpaceManDan · Oct 06, 2015 at 03:11 AM

Actually in version 5.2.0f3 it no longer says Raycasts... It now appears as: "Queries Hit Triggers" Uncheck if you want raycasts to pass through trigger colliders.

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
2

Answer by hameed-ullah-jan · Oct 24, 2018 at 11:37 AM

you can use the last parameter of the raycast function, put this "QueryTriggerInteraction.Ignore" as the last parameter in the raycast function.

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 ajdrew81 · Aug 11, 2015 at 02:00 AM

I recently had a similar problem.

Go to Edit -> Project Settings -> Physics2d and Uncheck the box that says "Raycasts Start In Colliders".

This will let you ignore the colliders on the gameobject casting them. This makes it so that you do not have to deal with layers (I find layers to be a very impractical way of selectively raycasting). It just ignores the collider on the gameobject casting the ray, so you can have multiple prefabs of players/enemies casting rays and hitting each other, but not themselves.

However, to ignore trigger colliders, please use Okido's suggestion.

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 killer-zog · Nov 09, 2015 at 04:10 PM 0
Share

Wow, thanks, this saved me a lot of headache.

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

22 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

Related Questions

Should Physics.Raycast() hit a Trigger on a disabled GameObject? 1 Answer

How to SetActive an object with a raycast? 2 Answers

Raycast not updating inside a trigger collider 0 Answers

active script from distance 3 Answers

Is there a way to detect if an object is being hit by a raycast? 2 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