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 Jiraiyah · Jan 12, 2015 at 02:37 PM · raycastaccuracyhitpoints

accuracy problem with ray cast

Hi I'm trying to instantiate an empty game object in the place a direct vertical ray hit the objects in the editor mode, now here is the problem

alt text

the blue arrow shows the direction of the ray, the yellow arrow is the surface of the object, the object that is marked by red arrow is the one that is created but the one with green arrow is the place that is should have been.

here is the code :

 var hitInfo = Physics.RaycastAll(new Vector3(x,int.MaxValue,z), -Vector3.up);
 if (hitInfo.Length > 0)
 {
     Debug.Log("We hit something");
     foreach (var hit in hitInfo)
     {
         var slp = 180 - Vector3.Angle(hit.normal, -Vector3.up);
         if (slp <= 90 + slope)
         {
              GameObject go = new GameObject("Node_"+x+"_"+hit.point.y+"_"+z);
              go.transform.position = new Vector3(x, hit.point.y, z);
              go.AddComponent<Node>();
         }
 
      }
 }

What am I doing wrong? or if the stuff is correct, how can I solve this?

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 meat5000 ♦ · Jan 12, 2015 at 02:41 PM 0
Share

What is the numerical difference between expected and actual placement?

avatar image Jiraiyah · Jan 12, 2015 at 03:17 PM 0
Share

in that example it was 0.3 units, farther testing is even worse

alt text

That big sphere in the red arrow is the exact position of hitInfo.point in simple raycast on the same vector ! it jumps to the side of the geometry totally out of the direction I cast the ray

this is unity 5 x64 b18 by the way not sure if it's a bug in that version or what

alt text

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Paulius-Liekis · Jan 12, 2015 at 02:45 PM

You use int.MaxValue as starting distance. That could lead to precision issues, if we're talking about small numbers. Try using smaller offset and see if the problem goes away.

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 KurtGokhan · Jan 12, 2015 at 02:47 PM

I think you shouldn't use int.MaxValue in this situation. Have a max height defined that suits your needs. If it is too big like int.MaxValue it may cause floating point errors.

 var hitInfo = Physics.RaycastAll(new Vector3(x,1000,z), -Vector3.up);

You can increase 1000 to suit your needs. Your game shouldn't take more space than 100000 anyways. That is going to cause floating point errors.

Comment
Add comment · Show 4 · 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 Jiraiyah · Jan 12, 2015 at 03:21 PM 0
Share

Ok, that change solved the accuracy but what if for example I import a DE$$anonymous$$ from something like Grome, there will be huge mountains like 4000$$anonymous$$ there!

avatar image Jiraiyah Jiraiyah · Jan 12, 2015 at 03:25 PM 0
Share

Ah tested more 1,000,000 is pretty big for every terrain I think and it still has nice accuracy, think that is good enough even for AAA games to generate navigation grids proceduraly now :D (the thing I'm working on is a sand box for AI :D)

Thanks for help

avatar image Paulius-Liekis · Jan 12, 2015 at 03:32 PM 0
Share

Well..if you have really big maps, then you end up doing workarounds. People who do something like space simulators/shooters where they have really big distances, they end up splitting it into multiple spaces and then simulating everything in your "local" space in order to avoid very big numbers.

avatar image KurtGokhan · Jan 12, 2015 at 04:24 PM 0
Share

Yeah I am also actually working on a procedural AI and I encounter problems like this. For example my game space should be at distance 100,000 to 120,000 to origin. Then I simply subtract 100,000 and it becomes from 0 to 20,000. Workarounds like this are necessary.

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

28 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

Related Questions

Accuracy not working properly 1 Answer

How to give your enemy gun inaccuracy 1 Answer

More precise Vector3 2 Answers

How to Implement First Shot Accuracy? 2 Answers

Problem in Shooting Accuracy 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