Beta: Spherical Pathfinding + local space

Hi there, Ive been using A* for several years now and love it.

I’ve been toying around with this idea I’ve had for an RTS game that would make use of spherical worlds. I was wondering if it would be possible to create a custom path script that combines the local space graph functionality in the moving demo with the AI Path aligned to surface script together into one that would allow units to path on the planet while the planet is moving in space.

I sort of naively started playing around with the idea by making a new script based off of AIPathAlignedToSurface that just adds the LocalSpaceRichAI contents. Looks something like this:


using Pathfinding;
using UnityEngine;

public class LocalSpaceAIPathAlignedToSurface : AIPathAlignedToSurface
{
    /// <summary>Root of the object we are moving on</summary>
    public LocalSpaceGraph graph;

    protected Vector3 ClampPositionToGraph (Vector3 newPosition) {
        RefreshTransform();
        // Clamp the new position to the navmesh
        // First we need to transform the position to the same space that the graph is in though.
        var nearest = AstarPath.active != null? AstarPath.active.GetNearest(graph.transformation.InverseTransform(newPosition)) : new NNInfo();
        float elevation;

        movementPlane.ToPlane(newPosition, out elevation);
        return movementPlane.ToWorld(movementPlane.ToPlane(nearest.node != null ? graph.transformation.Transform(nearest.position) : newPosition), elevation);
    }

    void RefreshTransform () {
        graph.Refresh();
        richPath.transform = graph.transformation;
        movementPlane = graph.transformation.ToSimpleMovementPlane();
    }

    protected override void Start () {
        RefreshTransform();
        base.Start();
    }

    protected override void CalculatePathRequestEndpoints (out Vector3 start, out Vector3 end) {
        RefreshTransform();
        base.CalculatePathRequestEndpoints(out start, out end);
        start = graph.transformation.InverseTransform(start);
        end = graph.transformation.InverseTransform(end);
    }

    protected override void OnUpdate (float dt) {
        RefreshTransform();
        base.OnUpdate(dt);
    }
}

Would something like this be feasible, or would it be a transformation nightmare? And if so, how could I implement it?
Thanks!

Hi

It is possible to do this, I think. But it might be a bit tricky. The local avoidance system would also need to work in graph-space to avoid trying to take into account the velocity of the moving planet. So you’d need to override and change any interactions related to that.
I’m not sure if that’s everything, though. I haven’t done anything like this myself.