There is some unit vector, which is a coordinate in a spherical space. It is necessary to obtain from it 4 vectors diverted in different directions (right, left, forward, backward) by a certain number of degrees. For these actions I use the following code:
Vector3 center = point;
Vector3 left = Quaternion.Euler(-30, 0, 0) * center;
Vector3 right = Quaternion.Euler(30, 0, 0) * center;
Vector3 back = Quaternion.Euler(0, 0, -30) * center;
Vector3 front = Quaternion.Euler(0, 0, 30) * center;
The problem is that this works when point is equal or close to Vector3.up. When deviating from the vertical position, the lateral vectors begin to "stick together".
Here is a visualization of what I need:
Test code is attached:
using System.Collections;
using UnityEngine;
public class Test : MonoBehaviour
{
public GameObject centerGO;
public GameObject leftGO;
public GameObject rightGO;
public GameObject backGO;
public GameObject frontGO;
ArrayList list = new ArrayList();
void Start()
{
SetCenterPoint(Vector3.up);
}
void Update()
{
DrawDebugRays();
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
SetCenterPoint(hit.point);
}
}
void SetCenterPoint(Vector3 point)
{
Vector3 center = point;
Vector3 left = Quaternion.Euler(-30, 0, 0) * center;
Vector3 right = Quaternion.Euler(30, 0, 0) * center;
Vector3 back = Quaternion.Euler(0, 0, -30) * center;
Vector3 front = Quaternion.Euler(0, 0, 30) * center;
centerGO.transform.position = center;
leftGO.transform.position = left;
rightGO.transform.position = right;
backGO.transform.position = back;
frontGO.transform.position = front;
list.Clear();
list.Add(center);
list.Add(left);
list.Add(right);
list.Add(front);
list.Add(back);
}
void DrawDebugRays()
{
for (int i = 0; i < list.Count; i++)
{
Color color = Color.red;
switch (i)
{
case 0:
color = Color.green;
break;
case 1:
case 2:
color = Color.blue;
break;
}
Debug.DrawRay(Vector3.zero, (Vector3)list[i], color);
}
}
}