Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
11 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 Jer_J · Jul 09, 2015 at 12:53 PM · raycastmeshtilemapheightmapheight

Getting multiple heights at same (x,y) coordinate

So I've created a model landscape on blender that contains an underpass. The game that I'm making involves a TileMap (grid-based system). Each tile will contain information about its location (x,y coordinates, height, tile type etc...) The problem I've run into is that most threads talk about utilizing RayCasting in order to get height information, but my model is one mesh containing one collider and raycasting (as far as I know) cannot bypass a "single layer of material". My question is how can I acquire height information at this x,y point for both the underpass and the bridge above? Should I go back into blender and separate the model so each item can have separate colliders and use tag, or is there another method I should look into that might work efficiently? I want to target mobile platforms so I'd be great if there resource sparing methods out there!

EDIT:: Thanks to @Nischo for the answer, I've implemented the Physics.RayCastAll method into my program in the following manner:

 void CreateTileMap(){
         Debug.Log ("Create TileMap is called"); 
          
 
 
         int numXYtiles = terrainX * terrainZ; 
 
          
         RaycastHit[] detects; 
         float tileHeight; 
 
         Vector3 detectedHeight; 
         Vector3 rayOrigin = new Vector3 (0f, 15f, 0f); 
         Vector3 rayDirection = new Vector3 (0, -1, 0); 
         for (int x = 1; x < (terrainX*2); x = x + moveUnit) {
 
             rayOrigin.x = (float) x;
             //Debug.Log (rayOrigin.x); 
 
             for (int z = 1; z < (terrainZ*2); z = z + moveUnit){
 
                 rayOrigin.z = (float) -z; 
                 //Debug.Log (rayOrigin.z); 
                 detects = Physics.RaycastAll(rayOrigin, rayDirection); 
 
                 for (int i = 0; i < detects.Length; i ++) {
                     //Debug.Log (i); 
                     RaycastHit detect = detects[i]; 
                     Debug.Log (detect.distance); 
                      
                     detectedHeight = new Vector3(rayOrigin.x, rayOrigin.y - detect.distance, rayOrigin.z); 
                     newSphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); 
                     newSphere.transform.position = detectedHeight; 
 
 
 
 
                 }
 
                 cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                 cube.transform.position = rayOrigin; 
 
                  
                 
 
                 
 
                 }
 
 
             }
         }

I've also implemented a Debug.Log(detects.Length) to check whether multiple hits were detected and unfortunately all the values were 1. So only the first hit was registered, for more clarity I've attached a visualization here:

alt text

So as you can see the underpass has no spheres and therefore is not being detected. Any way around this?

unityanswersquestion.png (491.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

Answer by Nischo · Jul 09, 2015 at 01:06 PM

If i understand you correctly you want to get a point on your terrain, which might contain multiple "levels" of ground like a mountain and directly underneath a tunnel. Then yes, a simple Raycast might not be enough, but what you could do is raycast with Physics.RaycastAll sort the results by height and use the one thats most appropriate at that point.

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

2 People are following this question.

avatar image avatar image

Related Questions

3D Tilemap 1 Answer

Following Terrain Height? 2 Answers

'height' is not a member of 'UnityEngine.Collider'. 1 Answer

MonoBehaviour OnMouseOver does not work with mesh colliders. 0 Answers

Pointcast? - Raycast Point X from same Point X 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