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 alfchee · Jul 15, 2012 at 04:27 AM · raycast2d gameraycasthitmesh collider

Does work the raycast on a mesh collider?

Hello everybody!!

I found some similar questions, but or I don't understand the answer or does not solve my situation.

I have a mesh collider and when I try to raycast to it, I dont success; if I replace the mesh collider with a primitive collider (box collider) then I get the raycasthit object. I'm making the ray from the camera.

Is that a bug? there are solutions?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Eric5h5 · Jul 15, 2012 at 05:13 AM

Raycasts work fine with mesh colliders, and there is no bug. Either your raycast or mesh collider is wrong somehow.

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 alfchee · Jul 15, 2012 at 10:29 PM 0
Share

Well. I'm using the 2DToolkit, and it creates the mesh collider for the sprites, but when I raycast to it it doesn't work. Here is the function I use, but I guess is not the problem:

[code]

GameObject GetObjectClicked()

{

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

RaycastHit hit;

if(Physics.Raycast(ray, out hit))

return hit.collider.gameObject;

else

return null;

}//GetObjectClicked() [/code]

avatar image Eric5h5 · Jul 15, 2012 at 11:15 PM 0
Share

This site doesn't use [code] tags; ins$$anonymous$$d put 4 spaces in front of each line. See the syntax for $$anonymous$$arkdown. Anyway, I haven't used 2DToolkit; maybe the winding order needs to be reversed or something, since raycasts won't hit the back sides of polygons.

avatar image
0

Answer by alfchee · Jul 17, 2012 at 01:00 AM

You where right, the raycast was fine, I wrote in the forum of 2DToolkit, and somebody told me this

Set "collider cap" on the mesh colliders, and commit your sprite collection. By default no cap is generated.

So I set the "Collider Cap" to "Front" and now works.

Thanks for the help!

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

Problems with 2D RaycastHit.Collider 2 Answers

RayCastHit returns Untagged for a Tagged Item, when using a Mesh Collider. 1 Answer

Raycasting will not hit some imported meshes with mesh colliders? 2 Answers

Using raycast and collider to increase int 1 Answer

NullReference when checking tag via Raycast. How to solve this? 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