微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

UNITY3D:在没有光线投射的情况下获得步进

如何解决UNITY3D:在没有光线投射的情况下获得步进

我已经开始讨论地形法线,但我认为要找到具体的解决方案,我需要了解为什么我在地图中有 2 个不同的坡度角。 我需要在地面上了解坡度角超过35度的地方。 我尝试使用terraindata.GetStepness 函数,但结果不正确。 通过 Raycast 和 Vectro3.Angle 函数,我得到了不同且更准确的结果。 由于看到了各种关于成功使用GetStepness函数的讨论,我不明白为什么我必须有奇怪的结果。 我附上代码和截图。 谢谢你们! Angle

更新中:

        RaycastHit hit;
    Ray raggio = Camera.main.ScreenPointToRay(Input.mousePosition);
    Vector3 posiz; // = new Vector3(36,15f,7);
    //if (Physics.Raycast(posiz + (Vector3.up * 5),Vector3.down,out hit,Mathf.Infinity,MyGLB_E.layer_Terreno))
    if (Physics.Raycast(raggio,MyGLB_E.layer_Terreno))
    {
        posiz = hit.point;
        Terrain at = Terrain.activeTerrain;
        float normalizedX,normalizedY; Vector3 normale;
        hPoint = hit.point;
        posizp = new Vector3(posiz.x,at.terrainData.GetInterpolatedHeight(posiz.x / at.terrainData.size.x,posiz.z / at.terrainData.size.z),posiz.z);
        normalizedX = posizp.x / at.terrainData.size.x ;
        normalizedY = posizp.z / at.terrainData.size.z ;
        normale = at.terrainData.GetInterpolatednormal(normalizedX,normalizedY);
        
        hpointAnGolo = at.terrainData.GetSteepness(normalizedX,normalizedY) ;          
        hString = "TERRAINDDATA (Green):\n\rSTEPnesS : " +  hpointAnGolo.ToString()  + "\n\rNMap : " +  normale + "\n\rAT : " + posizp;
        hN = normale;
        normale = hit.normal;
        hN0 = normale;
        hString0 = "RAYCAST (Red)\n\rANGLE UP : " +  Vector3.Angle(normale,Vector3.up).ToString() +  "\n\rNMap : " + hit.normal + "\n\rAT : " + hit.point;
    }

在 GIZMO 上:

        GUIStyle style = new GUIStyle(GUI.skin.label);
    style.alignment = TextAnchor.MiddleLeft;
    Handles.Label(hPoint,hString0 + "\n\r\n\r" + hString,style);
    Gizmos.color = Color.green;
    Gizmos.DrawRay(posizp,hN * 1);
    Gizmos.color = Color.red;
    Gizmos.DrawRay(hPoint,hN0 * 0.5f);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。