Я задавался вопросом, как я могу найти поворот на точке местности с помощью Vector3?
public class Grid : MonoBehaviour
{
public Terrain terrain;
public Vector3 area;
[HideInInspector]
public List<Vector3> points;
public GameObject prefab;
public float minDistance;
private void Start()
{
terrain = GetComponent<Terrain>();
#region PlaceVector3
for (int x = 0; x < area.x; x++)
{
for (int y = 0; y < area.y; y++)
{
for (int z = 0; z < area.z; z++)
{
Vector3 pos = new Vector3(x, y, z);
pos.y = terrain.SampleHeight(new Vector3(x, y, z));
points.Add(pos);
}
}
}
#endregion
}
private void Update()
{
Spawn(prefab);
}
private Vector3 GetMousePos()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
return hit.point;
}
else return Vector3.zero;
}
public void Spawn(GameObject obj)
{
if (Input.GetMouseButtonDown(0))
{
Vector3 tempVec = Vector3.zero;
foreach (Vector3 vec3 in points)
{
if (Vector3.Distance(vec3, GetMousePos()) < Vector3.Distance(tempVec, GetMousePos()))
tempVec = vec3;
}
RaycastHit hit;
if (Physics.Raycast(tempVec, Vector3.up, out hit, 1f))
{
print(hit.transform.gameObject);
}
GameObject GO = Instantiate(obj, tempVec, Quaternion.identity);
//TODO INSERT THE ROTATION OF THE TERRAIN ROTATION AT POINT TEMPVEC
}
}
}
Здесь вы можете увидеть мой код, здесь я просто рисую сетку, а затем получаю высоту точки, получая доступ к данным ландшафта. Мой вопрос в том, как я могу получить вращение (нормальное) в значение Quaternion, если я знаю точку. Я попытался получить вращение с помощью Vector3.Angle(tempVec, Vector3.up)
, но, похоже, это не сработало.