Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Jer_J · Jul 21, 2015 at 11:34 AM · raycastraycasthitglitchcreateprimitive

Unity Glitch for Creating Primitives via RayHit info?

Hi,I have code that uses a RayCast and creates a primitive object at the location. To create the primitive I set the position of it to (x, rayOrigin.y - hit.distance, z). Theoretically this should work fine. When I run the code all the squares I create seem to be in the right place visually, but, when I click on them, the inspector reports the x and z values correctly but the y value is completely off!

alt text

The y coordinate for this one is -2.2053 (but its actually at 0)

alt text

The y coordinate for this one is -7.1525 (but it's actually at 0 as well!)

Something that I checked before posting is whether the model might be rotated, and it's not, its right on the x and z axis, and perpendicular at all points to the y axis, therefore there should not be any changes in height due to rotation. In addition in other points of the map where the height of the floor is not 0, the height of the created object is correct (uh what?).

I'm worried it might cause miscalculations, say, if I wanted to store this height and use it later to create an object or vertex. Is this a known glitch, or is it something I didn't take account for?

P.S: I don't know if this plays a role but the floor is a flat grid made on blender with some areas of extrusion (areas shown in pic are flat and not extruded).

unityweird2.jpg (111.8 kB)
unityweird1.jpg (135.1 kB)
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
1
Best Answer

Answer by Owen-Reynolds · Jul 21, 2015 at 09:46 PM

The two things (raycast and spawning) aren't connected. Break it into parts. One part has the problem.

Raycasts hit colliders where they hit, and tell you where. It doesn't matter what you later want to use the hit point for. Either there's a problem with your Raycast, or you aren't reading RayHit correctly, or there's a problem with how you place the objects. Check the usual "raycast hitting in wrong spot" questions. Test to see the point is correct. If that's all working, check the "object not placed at correct location" questions.

But, why not just use hit.point? Your distance formula is only correct if the ray is always aimed straight down (but hit.point is still easier to use.)

Comment
Add comment · Show 1 · 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 Jer_J · Jul 22, 2015 at 09:07 PM 0
Share

thanks for the response! The initial reasoning behind the cubes and spheres was to visualize what RayCastHit was hitting, so they were placeholders. I didn't realize that the creation of the placeholder itself may present potential for error. I used the same hit.transform.position (should probably change to point later) method and stored it in a List and it seems that the RayCastHit did report the correct values so it ended up be all okay!

But I am still curious as to why the Vector3 was stored correctly (y = 0) but when used with cube.transform.position gave a very negative value (maybe its due to the way 0 is stored in float, -0 and 0).

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Is this way of making a raycast correct 2 Answers

RaycastHit2D.collider is null - why? 1 Answer

How do I change the raycasthit material back? 1 Answer

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

Physics.Raycast not hitting anything 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