• 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
2
Question by chartinboy · May 07, 2015 at 11:48 AM · raycast

Unity3D raycast ignore self

I have an object raycasting, from transform.position forward, however the raycast is hitting the original object. I can't switch layers, as I have many of these objects, all of which need to check for eachother.

I originally thought it was because I had a convex mesh collider of the object, so I tested out just a box collider, however it is still just hitting itself. Where have I gone wrong here?

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

Answer by komodor · May 07, 2015 at 12:00 PM

Unity 4.6.1 has the option turn on/off the ability to detect a collider that overlaps the start of any 2D line/raycast in Edit -> Project Settings -> Physcis 2D -> Raycasts Start In Colliders.

http://stackoverflow.com/questions/24563085/raycast-but-ignore-yourself

i am generally using the second option, because i usually need ignore more than one collider

you can also disable the collider before raycast and enable after (edit: actually this worked before, then, during 4.6 evolution there was time it wasn't working and i am not sure if it works in u5)

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 chartinboy · May 07, 2015 at 12:04 PM 0
Share

I've seen that a couple times - sounds like that's only a Unity 2D thing though? I'm working on a 3D project.

avatar image komodor · May 07, 2015 at 12:06 PM 0
Share

well check the stackoverflow link then, i guess that's all you can do

avatar image Adil192 · Feb 21, 2021 at 10:49 PM 0
Share

Necroing this thread to say that it's "Queries Start In Colliders" now. (I'm using Unity 2020.2.5f1)

avatar image
3

Answer by joshua-lyness · May 07, 2015 at 12:01 PM

do you need the box collider on the object? If you don't, then delete it.:)

If you do need it, what about physics.raycastAll? It will list all objects that collide with the ray, and then you could say that if it collides with an object with a tag not equal to "emitter" then it will have an effect...?

link text

Comment
Add comment · Show 2 · 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 chartinboy · May 07, 2015 at 12:05 PM 0
Share

I definitely need a collider on it. RaycastAll sounds like it might work for me, I'll try that!

avatar image joshua-lyness · May 07, 2015 at 12:10 PM 0
Share

ok. Tell me if it does... im intrigued! :)

avatar image
2

Answer by dudester · May 07, 2015 at 05:00 PM

ok well first make sure you are raycasting from inside the collider make sure there are no colliders on the outside of the object and you should be golden, again the origin of the collider needs to be inside the collider otherwise itll collide with the object , seeing as you are raycasting against objects in the same layer you cant use layermasks so yeah let me know if that works for you.

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 chartinboy · May 07, 2015 at 05:32 PM 0
Share

Aye, I'd found out about that already. The origin of the raycast is inside the mesh, and it is a single collider on the gameObject, and even in a test scene with just two objects this problem occurs.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

I use Vector3.Reflect but it didn't work correctly 0 Answers

Long-distance physics 0 Answers

Unity 4.3: wrong object responds to click. 1 Answer

Raycast Shooting problem 2 Answers

Check if player object is right above this object 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