Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Classic-Niall · Jul 29, 2018 at 10:14 AM · raycastcollider3dnavmeshnavigation

RayCast not accurate on non-colliders (3D)

Okay, so here's the breakdown.

This wasn't an issue before, and I don't know how long ago it became an issue.

I have a level designed in Blender and imported. It has a Navigation mesh to detect RayCast and to move the character.

I also have different objects, items to pick up, which have colliders on them.

Now, when I click, the Raycast goes out. As soon as I click, I return the transform position of wherever/whatever is clicked. Objects with colliders return the correct position, whereas, without a collider, it is the point, plus some extra?

Nothing else happens at this moment other than returning a value.

For instance, with the collider, the characters left eye returns (-8.8, 1.8, 17.1), but without it is (-8.9, -1.5, 11).

I have another object which is sat on the ground. The coordinates are (-13, 0.5, 13.7) with collider and (-14.8, -1.5, 9.8) without collider.

Even just moving the mouse off the object without turning off the colliders makes the "jump", and clearing the navmesh makes no difference.

The constant in this is the -1.5 value.

I'd post my code, but I don't know how, however, it is rather basic/generic.

Comment
Add comment · Show 2
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 Classic-Niall · Jul 29, 2018 at 04:23 PM 0
Share

The most obvious solution is to add a mesh collider to my level, but my level is complex, with mountains and valleys (although on a 20x20 area). I want to keep the "strain" as low as possible, as it's a mobile game.

I just find it odd why it suddenly started happening, especially when I've seen others not have this issue.

avatar image Harinezumi · Jul 29, 2018 at 06:34 PM 0
Share

Hey!

I would like to help, but what you are writing really confuses me: raycasts do use physics, and as such they don't work at all if an object doesn't have a collider. Are you talking about Physics.Raycast() call? Or do you use a different system? Is it possible that sometimes you use raycastHit.point while other times raycastHit.collider.transform.position? These are not the same things (the first tells you where the raycast hit, the second tells you the position of the object hit, the center so to say).
Also, Navmesh has nothing to do with physics, and so raycasts.

So I think you will have to add colliders for raycasts, but there are a few options. First of all, mark your terrain static, that will help a lot with the simulation. Then, if you can model your environment with Unity's terrain system, that already has a collider which is relatively efficient. Finally, you can also try some more complex techniques, like turning physics on and off based on areas, but that might not help with performance.

Finally, it would definitely help if you posted some code, the bugs are usually in the details. You can just copy-paste it into a post here, select it, and then click the code button (the one that has 101010 on it) to format it as code.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by OutOfRam · Jul 30, 2018 at 03:15 PM

Hello,

I think you may be confused about how the Unity Physics.Raycast system works. The unity raycast system casts a ray against all colliders in the scene and returns detailed information on what was hit. In that sense there is no way for a raycast to interact with an object that does not have a collider. It is my belief that the reason your values are shifting as described above when you turn off the collider is because the raycast is merely hitting a different collider in your scene. To test this, try printing not only the position of the raycast hit, but also the name of the game object to which the collider is attached.

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

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

Related Questions

How do I get nav agents to not collide with each other? 0 Answers

RayCast From Centre of Camera 1 Answer

Need help with Nav Mesh Agent getting "stuck" at high speeds 0 Answers

Check if position is inside a collider 5 Answers

Object reference not set to an instance of an Object? 0 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