Quantcast
Channel: Latest Questions by karl_
Viewing all articles
Browse latest Browse all 90

Set Vertices to Ground

$
0
0
I'm trying to set all the vertices of plane to match the height of the terrain. At the moment, it sets about half the plane to some random Y value and ignores the other half. I can't seem to figure out what's going wrong here. So far this is what I have: using UnityEngine; using UnityEditor; using System.Collections; public class GroundVertices : MonoBehaviour { [MenuItem("Tools/Ground Vertices")] static void Init() { Mesh m = (Mesh)((MeshFilter)Selection.activeTransform.gameObject.GetComponent(typeof(MeshFilter))).sharedMesh; Vector3[] verts = m.vertices; for(int i = 0; i < verts.Length; i++) { verts[i] = new Vector3(verts[i].x, verts[i].y + 100f, verts[i].z); RaycastHit ground = new RaycastHit(); if(Physics.Raycast(verts[i], Vector3.down, out ground)) { Debug.Log(ground.point.y + ground.transform.tag); verts[i].y = ground.point.y; } } m.vertices = verts; m.RecalculateNormals(); } }

Viewing all articles
Browse latest Browse all 90

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>