Off-mesh link for just climbing up and hopping down glitchy

  • A* version: 5.4.7
  • Unity version: 6000.0.67f1

I’m trying to use the off-mesh links with followerentities on a grid graph, (side note: I prefer AIPath because it follows the grid links correctly, I only want to use 4 way but it likes to cut corners. Edit: I switched back to AIPath, the smoothing was too glitchy for the strict movement I want. Sad to lost the off-mesh link compatibility)

This is for turn based movement.

I’m instantiating obstacles at the beginning of the level, then re-scanning which works, one of the obstacles is a level higher than ground, I want it to be part of the grid and have the followerentites simply climb up or hop down from it but the pathing costs seem incorrect, they’ll walk one less node than i expect, sometimes 2. I also have a method to draw a line around the outside of the movable area but around the climbable obstacles it gets very glitchy.

I’m also using the calculated path vectors to draw a line to show the move path to the player, but it just doesn’t work for the links. Even if the displayed path doesn’t work, clicking to climb up or down works but as I said the character usually moves a shorter distance than they should be able to.

The links look like this with no custom code, eventually i want a climb animation but for now i just want it to work correctly.

for movement i’m doing this:

ai.SetDestination(targetPosition);
            var path = ABPath.Construct(gameObject.transform.position, targetPosition, null);
            path.traversalConstraint.traversalProvider = gridInteractionUtilities.traversalProvider;
            path.traversalConstraint.graphMask = GraphMask.FromGraphName("Main Grid Graph");
            ai.SetPath(path);

            Pathfinding.ECS.AutoRepathPolicy newPolicy = new Pathfinding.ECS.AutoRepathPolicy();
            newPolicy.mode = AutoRepathPolicy.Mode.Never;
            ai.autoRepath = newPolicy;
            thisSurvivor.localEvents.RaiseStartMoving(this, EventArgs.Empty);
            ai.simulateMovement = true;

            await UniTask.WaitUntil(() => ai.reachedDestination == true);
            ai.simulateMovement = false;

            var constraint = NearestNodeConstraint.Walkable;
            constraint.graphMask = GraphMask.FromGraphName("Main Grid Graph");
            var nearest = AstarPath.active.GetNearest(transform.position, constraint).node;
            if (nearest != null)
            {
                var snapped = (Vector3)nearest.position;
                //snapped.y = transform.position.y;
                transform.position = snapped;
            }

for drawing the outline:

public virtual List<GraphNode> GetValidGridPositionInRange(int range, AbilityTargetType targetType)
        {
            UpdateObstacles();
            // Here you create a new path and set how far it should search. Null is for the callback, but the seeker will handle that

// i'm adding 1 to get the actual range, otherwise it ends up one short? for example a max range of 5 ends up being 4 without +1
            var cpath = ConstantPath.Construct(transform.position, ((int)range + 1) * 1000, null); 
            cpath.traversalConstraint.graphMask = GraphMask.FromGraphName("Main Grid Graph");

            if (targetType == AbilityTargetType.Move)
            {
                cpath.traversalConstraint.traversalProvider = traversalProvider;
            }

            AstarPath.StartPath(cpath);
            cpath.BlockUntilCalculated();

            var nodesToContourAll = cpath.allNodes.OfType<GridNodeBase>().ToArray();

            DrawContour(nodesToContourAll, targetType);
            

            var graphNode = cpath.allNodes;

            for (var i = 0; i < cpath.allNodes.Count; i++)
                Debug.DrawRay((Vector3)cpath.allNodes[i].position, Vector3.up, Color.red, 2f);

            return graphNode;
        }c


public virtual void DrawContour(GridNodeBase[] nodesToContour, AbilityTargetType targetType)
        {
            ClearContourPaths();

            if (nodesToContour == null || nodesToContour.Length == 0)
                return;
            
            var contourColour = GetRangeOutlineColour(targetType);
            rangeOutlineColour = contourColour;
            
            var grid = AstarPath.active.data.gridGraph;
            GraphUtilities.GetContours(grid, vertices =>
                {
                    if (vertices == null || vertices.Length == 0)
                        return;

                    if (contourPaths == null)
                        contourPaths = new List<PolylinePath>();

                    var contourPath = new PolylinePath();

                    for (var i = 0; i < vertices.Length; i++)
                    {
                        var linePos = new Vector3(vertices[i].x, 0.05f, vertices[i].z);
                        contourPath.AddPoint(linePos);
                    }

                    if (contourPath.Count > 1)
                        contourPaths.Add(contourPath);
                    else
                        contourPath.Dispose();
                },
                0.5f, nodesToContour);
        }

and for the movement path line:

if (start != lastStartMove ||
                end != lastEndMove ||
                movePath == null ||
                lastMoveRange != range)
            {
                movePath = ABPath.Construct(start, end, null);
                movePath.traversalConstraint.traversalProvider = traversalProvider;
                movePath.traversalConstraint.graphMask = GraphMask.FromGraphName("Main Grid Graph");
                AstarPath.StartPath(movePath);
                movePath.BlockUntilCalculated();
            }

            lastStartMove = start;
            lastEndMove = end;
            lastMoveRange = range;

            if (movePath.error || movePath.vectorPath == null || movePath.vectorPath.Count <= 1)
            {
                SetNodeSelectorVisualColour(invalidMovementLineColour);
                TooltipSystem.Hide();
                return;
            }
            float pathLength = 0f;

            for (var i = 0; i < movePath.vectorPath.Count; i++)
            {
                var newPoint = GetMainGridVisualPosition(movePath.vectorPath[i]);

                if (i > 0)
                    pathLength += Vector3.Distance(movePath.vectorPath[i - 1], movePath.vectorPath[i]);

                if (pathLength <= range + 0.2f)
                {
                    SetNodeSelectorVisualColour(validMovementLineColour);
                    MovementPolyLine.AddPoint(newPoint, validMovementLineColour);
                }
                else
                {
                    SetNodeSelectorVisualColour(invalidMovementLineColour);
                    MovementPolyLine.AddPoint(newPoint, invalidMovementLineColour);
                }
            }

Cheers

I’ve realised after some testing that the links don’t all seem to work, the links on the long side of the rock work find (my movement path drawing still doesn’t work on them though), the links on the short end of the rock don’t seem to work, the character always goes up or down from the side then around to the nodes on the short edges instead of just hopping off.

Still looking for help with this whole off mesh link think, I just want the connection to act like any other node to node link

If you could share a video of this happening that would help a lot. I’d like to make sure I’m understanding the issue correctly before I suggest anything.

Here’s a recording and some more screenshots for context, it’s just very inconsistent, I’m not sure what’s going on anymore.

Hey there, sorry for the delay, would you be able to send it again? The WeTransfer expired. I also see that this is in a subscene. Can you see if this happens without a subscene? I understand that may not work for your game but it’ll help narrow down where the issue may or may not be, especially since it’s inconsistent like you mentioned.

https://imgur.com/a/GS4xuVq

Here’s a new link. I’ll check if it happens in non subscenes when I get the chance.

Yeah I’m looking at the video and subsenes doesn’t seem related. I’m definitely of the mindset to test anyways but it doesn’t seem like it’s a likely cause. I think you may want to turn on path visualization and some of the other debug options. At one point they just walk through the rock which doesn’t seem… right.

Smoothing seems to play a possible role in the issue? Try turning off smoothing and seeing if that helps with it. That can also help to explain why it’s so inconsistent as well.

I’ll test the smoothing. The walking back and forth was me setting the end distance too small, which I’ve since increased.

My issue is that even before they move when calculating the path and drawing the line path, you can see it skips drawing the line between the nodes connected with the off mesh link nodes. Even though all I’m doing is taking the calculated path and drawing a line for each pair of vectors in the path array.

Also thanks, appreciate the help.

Ok I’ve improved a couple things and the movement line works a lot better, so seeing the path is a lot easier, I did have the debug paths on in the video although they were hard to see.

You can see in this image despite there being a better path it went around to the next link which is weird. excuse the naked people, I should really equip some armour when testing.

I’m not sure about the smoothing, they’re using the AIPath, does that have smoothing? They’re still walking through the rock instead of up the link onto it

I updated the graph mask to just the main graph which i think was the inconsistency issue, will keep testing.

edit: so it’s still doing this, odd.

In that first image, I wonder if this at all is because they’re on the same node as where the node link starts. See if they still behave like that if they’re one and two nodes away from the link? That second image makes sense though.

You may want to also see what the path costs are turning up as and making sure they line up with what would be expected for that specific path. Maybe there’s some pathing costs issue going on?

yeah it’s still weird from anywhere, I’ll test the path costs later