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 /
  • Help Room /
avatar image
0
Question by Alieno79 · Jan 19, 2021 at 07:39 PM · raycastangleterraindataslope

wrong slope on terraint

Hi everyone, I would like to understand in certain points of the terrain what its slope angle is, but I cannot understand the results I attach code (in update function) , screenshots and results

         RaycastHit hit;
         Ray raggio = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(raggio, out hit, Mathf.Infinity, MyGLB_E.layer_Terreno))
         {
 
             float normalizedX, normalizedY; Vector3 normale;
             indicatore.transform.position = hit.point;
             hPoint = hit.point;
             normalizedX = hit.point.x / terrainMesh.terrainData.size.x;
             normalizedY =   hit.point.z / terrainMesh.terrainData.size.z;
             normale = terrainMesh.GetComponent<TerrainCollider>().terrainData.GetInterpolatedNormal(normalizedX, normalizedY);
             hpointAngolo = terrainMesh.GetComponent<TerrainCollider>().terrainData.GetSteepness(normalizedX, normalizedY);            
             hString = "TERRAINDDATA:\n\rSP : " +  hpointAngolo.ToString() + "\n\rUP : " + Vector3.Angle(normale, Vector3.up).ToString() + "\n\rDW : " + Vector3.Angle(normale, Vector3.down).ToString() + "\n\rFW : " +  Vector3.Angle(normale, Vector3.forward).ToString() + "\n\rBW : " + Vector3.Angle(normale, Vector3.back).ToString() + "\n\rRG : " + Vector3.Angle(normale, Vector3.right).ToString() + "\n\rLF : " + Vector3.Angle(normale, Vector3.left).ToString();
 
             normale = hit.normal;
             hString0 = "RAYCAST\n\rUP : " +  Vector3.Angle(normale, Vector3.up).ToString() + "\n\rDW : " + Vector3.Angle(normale, Vector3.down).ToString() + "\n\rFW : " + Vector3.Angle(normale, Vector3.forward).ToString() + "\n\rBW : " + Vector3.Angle(normale, Vector3.back).ToString() + "\n\rRG : " + Vector3.Angle(normale, Vector3.right).ToString() + "\n\rLF : " + Vector3.Angle(normale, Vector3.left).ToString();
 
 
             //Debug.Log(hString0 + hString);
         }

Result: X Point left : RAYCAST

UP : 0

DW : 180

FW : 90

BW : 90

RG : 90

LF : 90

TERRAINDDATA:

SP : 0,5237671

UP : 0,5237671

DW : 179,4762

FW : 89,62936

BW : 90,37065

RG : 89,62936

LF : 90,37065

X Point Center RAYCAST

UP : 49,58921

DW : 130,4108

FW : 92,9032

BW : 87,0968

RG : 139,4404

LF : 40,55961

TERRAINDDATA:

SP : 13,1032

UP : 13,10318

DW : 166,8968

FW : 90,73031

BW : 89,2697

RG : 103,0821

LF : 76,9179

X Point Right RAYCAST

UP : 50,68999

DW : 129,31

FW : 92,8371

BW : 87,1629

RG : 39,45312

LF : 140,5469

TERRAINDDATA:

SP : 4,573589

UP : 4,573675

DW : 175,4263

FW : 87,25487

BW : 92,74513

RG : 93,65543

LF : 86,34457

Raycast is more precise of terraindata.. but both are imprecise

alt text

Tanks for your help, sorry for the english but i don't speak it

immagine.jpg (214.3 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
0

Answer by Alieno79 · Jan 20, 2021 at 01:29 PM

ok, i found problem in get normal... alt text

this is code in update :

         RaycastHit hit;
         //Ray raggio = Camera.main.ScreenPointToRay(Input.mousePosition);
         Vector3 posiz = new Vector3(36.271f, 11f, 6.72780f);
         if (Physics.Raycast(posiz + (Vector3.up*5),Vector3.down, out hit, Mathf.Infinity, MyGLB_E.layer_Terreno))
         {
 
             float normalizedX, normalizedY; Vector3 normale;
             //indicatore.transform.position = hit.point;
             hPoint = hit.point;
             normalizedX = posiz.x / terrainMesh.terrainData.size.x;
             normalizedY =  posiz.z /  terrainMesh.terrainData.size.z;
             normale = terrainMesh.GetComponent<TerrainCollider>().terrainData.GetInterpolatedNormal(normalizedX, normalizedY);
             hpointAngolo = terrainMesh.GetComponent<TerrainCollider>().terrainData.GetSteepness(normalizedX, normalizedY);            
             hString = "TERRAINDDATA:\n\rSP : " +  hpointAngolo.ToString() + "\n\rUP : " + Vector3.Angle(Vector3.up,normale ).ToString() + "\n\rDW : " + Vector3.Angle(normale, Vector3.down).ToString() + "\n\rFW : " +  Vector3.Angle(normale, Vector3.forward).ToString() + "\n\rBW : " + Vector3.Angle(normale, Vector3.back).ToString() + "\n\rRG : " + Vector3.Angle(normale, Vector3.right).ToString() + "\n\rLF : " + Vector3.Angle(normale, Vector3.left).ToString() + "\n\rNR : " +  normale;
             hN = normale;
             normale = hit.normal;
             hN0 = normale;
             hString0 = "RAYCAST\n\rUP : " +  Vector3.Angle(normale, Vector3.up).ToString() + "\n\rDW : " + Vector3.Angle(normale, Vector3.down).ToString() + "\n\rFW : " + Vector3.Angle(normale, Vector3.forward).ToString() + "\n\rBW : " + Vector3.Angle(normale, Vector3.back).ToString() + "\n\rRG : " + Vector3.Angle(normale, Vector3.right).ToString() + "\n\rLF : " + Vector3.Angle(normale, Vector3.left).ToString() + "\n\rNR : " + hit.normal;
 
         }


this is code in gizmo :

         GUIStyle style = new GUIStyle(GUI.skin.label);
         style.alignment = TextAnchor.MiddleLeft;
         Handles.Label(hPoint, hString0, style);
         Handles.Label(hPoint + Vector3.right, hString, style);
         Gizmos.color = Color.green;
         Gizmos.DrawLine(hPoint,hPoint + ( hN * 1));
         Gizmos.color = Color.red;
         Gizmos.DrawLine(hPoint, hPoint + (hN0 * 1));


why normal of terraindata is different to normal of raycast?

Tanks for your help


immagine.jpg (160.6 kB)
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

202 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make a character controller slide down when the angle of a slope is over 45 degrees 1 Answer

Help Converting Raycast Into a Raycast2D 0 Answers

Wall sliding with characterController against an edge 0 Answers

How to change ray angle of inclination 1 Answer

How do i limet angles of a raycast? 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