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
2
Question by malkere · May 02, 2015 at 02:29 PM · raycastvector3raycasthitpointvoxel

RayCast Hit Point rounding itself...?

I've written a voxel system that smooths the top of a cubes four vertices rather than just maxing them to their corners. this is based on simplexnoise so sometimes a value is only 0.0001 above the integer or below, etc.

90% is working nicely at this point. I'm running waves of debugs on this code since last night and I've found that my raycast hit.point is only sending numbers to the tenth (1.1, 1.2) for collision math with makes my 15.95 turn into a 16, so it thinks I've hit an empty cube, when I really hit the 15.

here is the debug:

cube: (3.0, 16.0, 2.0) hit: (3.9, 16.0, 2.5) height: 15.95

I could just round everything to the tenth, but.... can hit.point not go anymore specific than this? Is this a setting somewhere?

Thank you.

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

1 Reply

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

Answer by fafase · May 02, 2015 at 02:39 PM

Only the debug is rounded, the actual value is not. For instance, use a public variable to receive the hit point and you will see some more accurate values.

 public override string ToString ()
 {
     return UnityString.Format ("({0:F1}, {1:F1}, {2:F1})", new object[]{
           this.x,
           this.y,
           this.z
      });
 }

This is the ToString used by default in debug for Vector3. It only prints one decimal. If you want to see more accurate values use your own Debug:

 Vector3 v = hit.point;
 Debug.Log(v.x+", "+v.y+", "+v.z);

this should print out more accurate values.

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 malkere · May 02, 2015 at 02:53 PM 0
Share

you're right thank you. converting it to a Vector3 is giving more accurate debugs...

That doesn't solve my problem though. I'm seeing it from slightly over values too now will have to keep looking.

Thank you.

avatar image Bunny83 · May 02, 2015 at 03:34 PM 1
Share

@malkere What problem do you mean? No values are actually rounded, only those displayed in Debug.Log. The values itself have their maximum possible accuracy. $$anonymous$$eep in $$anonymous$$d that floating point values have a limited accuracy. The greater the values get the less significant digits behind the decimal points you have.

So everything you presented in your question is currently based on the wrong display of values in debug outputs. If you want to be sure that even very small numbers are displayed, use

 x.ToString("F20")
 // or in scientific notation:
 x.ToString("E9")


or something like that. With the scientific notation you can be sure to see the absolute maximum precision possible. I choose 8 because with a single-precision floating point value (float) you only have about 6-9 decimal digits.

If you still have problems, it at least isn't related to wrongly displayed values anymore ^^. If a value is somehow "rounded" it's most likely due to floating point precision issues.

Your question only addresses the debug output. So if you need any further help, you should ask a seperate question and include more details about your actual problem. You may leave a comment here with a link to your other question if you want us to have a look.

avatar image malkere · May 02, 2015 at 03:43 PM 0
Share

I found my major problem it was a silly mistake unrelated to the topic. It did sound like I was clai$$anonymous$$g that as an incomplete answer, but that's not what I meant. $$anonymous$$nowing now that the point was being rounded during debug meant what I thought was my problem was actually not so I needed to look else where.

Ultimately it was because my height array has an extra two points on the x and z axis for smoothing purposes and in one of the four functions that make use of that I was calling directly x,z ins$$anonymous$$d of x+1,z+1.

Fafase's help led me to find that rather than wondering what was up with my raycasts which are working fine.

Thank you for the kind follow-up though Bunny83. Born in 83? me too =D

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

19 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

Related Questions

Problem With Raycasthit Angle 0 Answers

Not getting right value; ScreenPointToRay 0 Answers

get the point directly above the raycast collision? 1 Answer

Using raycast - Why can't I get a variable on the object I hit? 1 Answer

raycastHit.point - How do I make it ignore colliders? 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