Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Noiz · Dec 22, 2014 at 03:44 PM · raycastvoxel

Returning a local hit from a raycast

I'm working with a voxel engine (voxity from the asset store), trying to add/remove blocks from a chunk that can move around. The problem I'm having is that the engine uses a grid system that assumes no rotation or movement to add/remove blocks.

I use Raycasts to determine where to alter the chunk. Raycasts return world coordinates, however, and the engine doesn't account for any kind of rotation causing rotated chunks to be incompatible with world coordinates. The movement issue is easy, but rotations is killing me!

The easiest solution I can think of is if I can get a local point on a mesh via raycasting. I know how to get the point a ray hit or the transform of the object it hit, but these both are in world coords. How can I get a local hit position?

If this isn't possible, what math would I need to learn to allow chunks to factor rotation in and produce accurate results on their local grids?

I'm currently studying computer science and have a reasonable amount of (novice) experience with c# and programming in general.

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

2 Replies

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

Answer by Owen-Reynolds · Dec 22, 2014 at 06:47 PM

The trick is, it's doesn't have anything to do with raycasting. The raycast gives you the data, and is done. You can do whatever math you want from there.

The real question, I think, is how to convert a world point into a transform's local coords. Use transform.InverseTransfromPoint.

Comment
Add comment · Show 2 · 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 Noiz · Dec 23, 2014 at 12:52 AM 0
Share

Wow. I can't believe how simple that was. Thanks! Guess I should have read the docs a little more.

avatar image Secret_Juice123 · Mar 07, 2021 at 02:38 AM 0
Share

6 years later and this answer saved my project. Thanks so much!

avatar image
0

Answer by jeffreymarkbaldridge · Dec 22, 2014 at 06:23 PM

http://docs.unity3d.com/ScriptReference/RaycastHit.html

This object will hold information about what your ray hit, including the transform, which includes rotational data. Look up some tutorials for raycasting in Unity. I have never worked with voxity though and wouldn't know if this would work for sure.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How would I find the closest Vector3 point to a given Ray? 2 Answers

RayCast Hit Point rounding itself...? 1 Answer

Knowing When a MeshCollider is Done Updating 1 Answer

[Unsolved] Raycast isn't casting 0 Answers

Voxel raycasting in world space 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