I need to create a navigation system between two points on a sphere, the problem is that since Unity's NavMesh does not work with spherical objects I have to calculate and manually position the object to its destination.
I created a logic that might not work, where calculating between the distance of the object and the destination plus the distance to the center would give me the position of the object, and reducing some percentage of the distance to the player would have a new position for move the object, but I could not go any further, because I can not convert this calculation to Vector3 for numerous problems I encountered.
Which way to do this? considering that I can not use Navmesh, and that the navigation of the object to the player has to be gradual.
Below is an image that represents the logic (Maybe nonsense, rs) that I imagined could work, and a script I started.
publicclassNavMeshController:MonoBehaviour{[Header("Settings")]
public GameObject toPoint; // Ponto de destino
public PlanetController sphere;
private Renderer renderer;
private float radious;
private float center;
void Start ()
{
renderer = sphere.GetComponent<Renderer>();
radious = getRadious();
}
void Update ()
{
// transform.Translate(toPoint.transform.position * Time.deltaTime, Space.World);
}
float distanceToPoint()
{
return Vector3.Distance(transform.position, toPoint.transform.position);
}
float distanceToCenter()
{
Vector3 center = renderer.bounds.center;
return Vector3.Distance(transform.position, renderer.bounds.center);
}
float getRadious()
{
SphereCollider sphereCollider = sphere.GetComponent<SphereCollider>();
return Mathf.Max(sphereCollider.transform.lossyScale.x, sphereCollider.transform.lossyScale.x, sphereCollider.transform.lossyScale.x) * sphereCollider.radius;
}
}