I am trying to get a object to the same x and z as the terrain below it. My method right now is to get Raycast to get the normal and then trying to mess with transform.eulerAngles
until they are the same. I fear this might be a little over my head though as I cannot figure this out for the life of me and I have been trying for several hours.
using UnityEngine; using System.Collections; public class example : MonoBehaviour { public Vector3 hitr; public Vector3 hitrn; void Update() { RaycastHit hit; Physics.Raycast(transform.position, Vector3.down, out hit); if (Physics.Raycast(transform.position, Vector3.down, 2)){ hitr = hit.normal; hitrn = hitr - transform.eulerAngles; transform.Rotate(hitrn.x, 0, hitrn.z); } } }