I am currently creating a RTS game where the map is a custom mesh mapped to the shape of a sphere. I then have a faux gravity towards the planet that holds the units to the planet.
I am currently working on the pathfinding for the units and right now I’m just trying to get the units to a waypoint (the location of a right click).
The units are children on the planet (for reasons explained at the end)
Right now I have:
Vector3 normal = GetComponent<Attract>().terrain normal;
Vector3 direction = waypoint - transform.position;
transform.rotation = Quaternion.LookRotation(Vector3.ProjectOnPlane(direction, normal), normal);
Waypoint is defined from a raycast that hits the planet.
My problem now is the planet the unit is on is both spinning in space and rotating around a sun. This is why I have made all the units children of the planet.
This spinning also means that the definition of the waypoint drifts off the surface of the planet and causes the unit to walk in weird circles.
basically, I’m trying to figure out how to define the waypoint as a child of the planet’s position, and then have the unit rotate towards that point (not concerned about slerp or anything). What I have now currently moves it in the right direction if the planet is not moving.
If anyone needs clarification or a greater breakdown of my code please let me know.