Jumping over obstacles on recast graph

Hi,

I’m trying to get my AI to jump over obstacles when running in my scene.
I have modified the standard link IEnumerator to start from his current position instead of first going to the node. This makes for smoother movement. The AI also plays an animation when he’s reached the start node.
The issue I’m currently having is that the AI jumps way ahead of time.
I’ve put the link2 start node(the one on the right where the gizmo is) right at the edge of the nav mesh but the AI jumps 1m or so before it reaches the start point.
As you can see on the picture. The link2 start node is on the edge. But I notice that the AI starts his jump on the connection where the 2 side edges connect to the one in the middle.
How can I change it so that it waits untill it reaches the node?

Edit:
As you can see here. Where my AI currently is, is the position where he starts his jump.
Quite a distance away from the point I want him to jump.
In this recast graph I have set the ‘max border edge length’ to 2. but that doesn’t seem to help.

Thanks!

Hi

You might need to lower the “end reached distance” field on your movement script.

Ow yeah! I didn’t think of that…
I’ll try it but I have found a workaround by now.
I first lerp to the point right before the obstacle. Then lerp across a curve. This way I can add a cruve height depending on the obstacle.

The curve code comes from the unity nav mesh package and I changed it to work for astar pro

   public IEnumerator StartJumpOverObstacle(RichSpecial link)
    {
        Vector3 currentPos = transform.position;
        float startTime1 = Time.time;
        while (Time.time < startTime1 + 1f)
        {
            transform.position = Vector3.Lerp(currentPos, link.nodeLink.StartTransform.position, Time.time - startTime1);
            yield return null;
        }
        _animator.SetInteger(JumpIndexHash, Random.Range(0, 2));
        _FlexNetworkAnimator.SetTrigger("Jump");
        Vector3 startPos = transform.position;
        Vector3 endPos = link.second.position /*+ Vector3.up*/ /** _agent.height*/;
        float normalizedTime = 0.0f;
        while (normalizedTime < 1.0f)
        {
            float yOffset = jumpCurve.Evaluate(normalizedTime);
            transform.position = Vector3.Lerp(startPos, endPos, normalizedTime) + yOffset * Vector3.up;
            normalizedTime += Time.deltaTime / 0.5f;
            yield return null;
        }
        //transform.position = link.second.position;
        _agent.traversingOffMeshLink = false;
    }

I also modified the Link 2 for easier visualization.

I changed it so that if you have ‘one way’ set to true. It visualizes where the start and end node is. To visually make it more clear where the one way really is. Also added 2 small spheres to the connected nodes to make it a bit more obvious where the connected sphere lies.
Also made the bezier height a public slider to quickly change the height to show a better curve over projectiles. Only visual stuff but it helps :slight_smile:

        public void OnDrawGizmos(bool selected)
        {
            Color color = selected ? GizmosColorSelected : GizmosColor;

            if (StartTransform != null)
            {
                Draw.Gizmos.CircleXZ(StartTransform.position, 0.4f, color);
            }
            if (EndTransform != null)
            {
                Draw.Gizmos.CircleXZ(EndTransform.position, 0.4f, color);
            }

            if (StartTransform != null && EndTransform != null)
            {
                Draw.Gizmos.Bezier(StartTransform.position, EndTransform.position, color, bezierHeight);
                if (selected)
                {
                    Vector3 cross = Vector3.Cross(Vector3.up, (EndTransform.position - StartTransform.position)).normalized;
                    if (oneWay)
                    {
                        Draw.Gizmos.Bezier(StartTransform.position + cross * 0.1f, EndTransform.position, color, bezierHeight);
                        Draw.Gizmos.Bezier(StartTransform.position - cross * 0.1f, EndTransform.position, color, bezierHeight);
                    }
                    else
                    {
                        Draw.Gizmos.Bezier(StartTransform.position + cross * 0.1f, EndTransform.position + cross * 0.1f, color, bezierHeight);
                        Draw.Gizmos.Bezier(StartTransform.position - cross * 0.1f, EndTransform.position - cross * 0.1f, color, bezierHeight);
                    }
                }
            }
            if (connectedNode1 != null)
            {
                Gizmos.DrawSphere((Vector3)connectedNode1.position, 0.1f);
            }
            if (connectedNode2 != null)
            {
                Gizmos.DrawSphere((Vector3)connectedNode2.position, 0.1f);
            }

        }
1 Like