AI shoots past its node 100% of the time

Hi i have an issue with the pathfinding over shooting part way through the path always moving about 20 units past a point then coming back for it. happens 100% of the time with multiple different units

Hi

Which movement script are you using? And which settings?

Grid Graph

image

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Pathfinding;
using System;

public class Agent : MonoBehaviour
{
    private Path path;
    private int currentWaypoint = 0;

    private Vector3 direction = Vector3.zero;
    [SerializeField] private Seeker seeker;
    [SerializeField] private CharacterController controller;

    [SerializeField] private Transform target;
    [SerializeField] private float nextWaypointDistance = 3f;
    [SerializeField] private float speed = 10f;

    private void Start()
    {
        if (seeker == null)
            seeker = GetComponent<Seeker>();
        GetNewPath();
    }

    private void FixedUpdate()
    {
        if (path == null)
        {
            return;
        }
        if (currentWaypoint >= path.vectorPath.Count)
        {
            return;
        }

        direction = (path.vectorPath[currentWaypoint] - transform.position).normalized * speed;
        controller.SimpleMove(direction);
        transform.LookAt(path.vectorPath[currentWaypoint]);

        if (Vector3.Distance(transform.position, path.vectorPath[currentWaypoint]) < nextWaypointDistance)
        {
            currentWaypoint++;
        }
    }

    private void GetNewPath()
    {
        seeker.StartPath(transform.position, target.position, OnPathComplete);
    }

    private void OnPathComplete(Path p)
    {
        if (!p.error)
        {
            path = p;
            currentWaypoint = 0;
        }
    }
}

Do you think you could upload a video of this happening? Preferably with gizmos visible.

1 Like

sure will ahve to be in about 30 mins or so though

sorry about the resolution i can retake with a higher res if you like, This happens with all agents when i duplicate this one.

i also downloaded the latest version from the website, non beta version as i was running into a null ref issue with the one from asset store

Hey,

I made a quick demo project to look at the issue here, and found the issue to be with your rotation.
transform.LookAt() will rotate x y and z. You normally don’t want this behaviour.
So you want to set the Y value to the same y of your agent.
something like this:

transform.LookAt(FlatVector(path.vectorPath[currentWaypoint]));

private Vector3 FlatVector(Vector3 vec)
    {
        return new Vector3(vec.x, transform.position.y, vec.z);
    }

Oh my, let me take a look at it and make the changes. didnt think it would effect the movement since im doing it based on direction of the vector from agent to next waypoint?

I personally havent used the character controller before and im wondering if its something that is needed for A* to work?

Oh that seemed to have fixed it but now it gets stuck on the corners. where abouts can i set the agents radius?

A* itself doesn’t really care. It all depends on the movementscript.
The movements scripts that come with A* support pretty much all setups.

  • Character controller
  • Rigid bodies
  • Normal colliders

Though if you make your own movement script it’s up to you to decide how you want implement it.

You can change the agent radius in the graph settings.

1 Like

I ended up changing the Diameter, im assuming this is the option thanks. ill play around with it some more. gets stuck on corners but im sure its something im doing wrong.

thanks for your help, i think i got it all sorted i converted over to a navmesh which seems to work much better

2 Likes