Moving a grid-graph collapses it into a line and disables 2D

My players travel in a moving ship, and I want to have enemies to be able to pathfind inside of this ship. I’m trying to have my A* graph copy the ship’s rotation/position without having to scan each frame.

I’ve tried to follow the doc’s page on relocating nodes, but copy the code seems to uncheck 2D mode for my graph in inspector, and rotate my graph to fit a 3D space:

    private void LateUpdate()
    {
        if (_gridGraph == null || !base.IsServerInitialized)
            return;

        Vector3 currentPos = Target.position;
        float currentRotZ = Target.eulerAngles.z;

        if (currentPos != _lastPosition || !Mathf.Approximately(currentRotZ, _lastRotationZ))
        {
            _lastPosition = currentPos;
            _lastRotationZ = currentRotZ;
            MoveGraph();
        }
    }

    private void MoveGraph()
    {
        AstarPath.active.AddWorkItem(() =>
        {
            _gridGraph.RelocateNodes(
                _lastPosition,
                Quaternion.Euler(0f, 0f, _lastRotationZ),
                _gridGraph.nodeSize
            );
        });

    }

I’ve tried experimenting with adding the following to my movement calcs, and this gives me something closer to what I was trying to achieve, but inverts my graph on the y axis.

            // set values
            _gridGraph.center = _lastPosition;
            _gridGraph.rotation = new Vector3(0f, 0f, _lastRotationZ);
            _gridGraph.is2D = true;
            _gridGraph.collision.use2D = true;

            // update the transform
            _gridGraph.UpdateTransform();

Inverted grid graph

Using unity 2022.3.25f1 and A* 5.3.7

Hi

The rotation should not be (0,0,alpha), it should be (alpha - 90, 270, 90).

1 Like

Oops I get it now, thanks!