Moving graph in 2D for AILerp

Hi, i need to make a LocalSpaceAILerp script (similar as LocalSpaceRichAI in an example scene) for 2d moving graphs. Tried to figure it out by myself but that’s too complicated for me. I’ll appreciate any help… Basically it is a 2D moving ships with the crew on them.

Hi

There’s no such included script. But essentially what you’d need to do is:

  1. Override the SearchPath function and run graph.transformation.InverseTransform(point) on both the start and end points of the path. This will transform the agent’s position from world space to some kind of graph space.
  2. Override the CalculateNextPosition function and make sure to run graph.Transform(point) on the returned value that comes from the path interpolator. This will transform the path point from graph space to world space.
  3. As with the LocalSpaceRichAI function, you’ll also need to add an update function to run graph.Refresh() every frame.

I have not tried this myself, but that’s the rough outline for how I would go about it.

Thanx for the reply. I guess im doing something wrong. Would you be able to check and correct my code please?

public class LocalSpaceAILerp : AILerp
{
//

Root of the object we are moving on
public LocalSpaceGraph graph;

    void RefreshTransform()
    {
        graph.Refresh();
        //interpolator.graphTransform = graph.transformation;
        //movementPlane = graph.transformation;
    }

    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);
    //}        
    public override void SearchPath()
    {            
        graph.transformation.InverseTransform(GetFeetPosition());
        graph.transformation.InverseTransform(destination);
        base.SearchPath();
    }
    protected override Vector3 CalculateNextPosition(out Vector3 direction, float deltaTime)
    {
        return graph.transformation.Transform(base.CalculateNextPosition(out direction, deltaTime));            
    }
    protected override void Update()
    {
        RefreshTransform();
        base.Update();
    }              
}

Hi

This will not modify anything. You’ll need to use the return values of those functions, and you’ll need to copy-paste most of the base implementation and modify that.
I’m guessing you are a C# beginner?

Not beginner, neither pro. Never had a chance to use override functions.) Would it be much and take much of your valuable time if ill ask you to do this?

Hi

Sorry, writing a larger custom script like that is not something I generally include in the support. However I am working on new movement scripts, and I aim to include this functionality in them by default. It may take some time for these to reach a release, though.

Hi,

Do you think they will reach a release anytime soon?

Hi

I’m focusing on smooth movement for the grid graph and recast graph first. The AILerp movement model will come after that, so unfortunately it will probably not be available in the near future.