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 ExtremePowers · Oct 22, 2014 at 01:16 PM · raycastmeshhit

Raycast bug?

My raycast method doesn't return true even though it hits something:

 if (Physics.Raycast(particles[par].position, Vector3.up, hit, terrainHeight)) {
     Debug.Log("True");
 }

It is hitting my terrain mesh, the reason I know this is happening is because I have used, Debug.DrawLine with the same direction, origin and height. Why isn't the function returning true?

Comment
Add comment · Show 4
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 imking · Oct 22, 2014 at 01:19 PM 0
Share

Your mesh have a collier ?

avatar image richyrich · Oct 22, 2014 at 01:31 PM 0
Share

Is your terrain set to a layer that ignores Raycasts?

avatar image richyrich · Oct 22, 2014 at 01:36 PM 0
Share

It might be that your Debug.DrawLine correctly showed a line from the origin to the terrain, but what if the line was upside down - (if the particle was lower than you thought) you would not be able to tell.

The fact that you are using Vector3.up as the direction suggests that your terrain is in the air - is that right?

avatar image ExtremePowers · Oct 22, 2014 at 02:26 PM 0
Share

$$anonymous$$y terrain is over the particles, as the particles are at y coordinate 0, but I would like to place them on the terrain and yes, the mesh has a mesh collider and is not hidden from raycasting with any tags.

1 Reply

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

Answer by Bunny83 · Oct 22, 2014 at 01:26 PM

Is your terrain upside down? If not, how can you possible hit it from below? The terrain collider is like a mesh collider. You can only hit the surface from "outside". That's actually true for any collider. However colliders like BoxCollider / SphereCollider are closed volumes so you usually aren't inside the collider, but if you are you wouldn't hit the collider either. Raycast and Linecast are "directed". If you reverse your raycast it should work, something like:

 if (Physics.Raycast(particles[par].position + Vector3.up*terrainHeight, -Vector3.up, hit, terrainHeight)) {
     Debug.Log("True");
 }

edit
Sorry had a typo ^^ fixed the code.

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

29 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

barycentricCoordinate always return vector(1,0,0) 0 Answers

Are tag settings passed down from Game Object parent to mesh child? 1 Answer

MonoBehaviour OnMouseOver does not work with mesh colliders. 0 Answers

Pointcast? - Raycast Point X from same Point X 0 Answers

i done this b4 but forgot :( touch screen 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