Pathfinding Pro and Mecanim AI

Hello!

I’ve tried to integrate the Pathfinding Project for my ai controlled Mecanim characters since a week now, but with no luck. I took Pat_AfterMoons example and removed the “click move” stuff:

protected Seeker seeker;
protected Animator animator;

protected Locomotion locomotion;

// The calculated path
public Path path;

// The AI's speed per second
public float speed = 1;

// The max distance from the AI to a waypoint for it to continue to the next waypoint
public float nextWaypointDistance = 3;

// The waypoint we are currently moving towards
private int currentWaypoint = 0;

// Use this for initialization
void Awake()
{
    seeker = GetComponent<Seeker>();
    animator = GetComponent<Animator>();
    locomotion = new Locomotion(animator);
}
void Start()
{
    SetDestination(FindObjectOfType<Player>().transform.position);
}
protected void SetDestination(Vector3 pos)
{
    seeker.StartPath(transform.position, pos, OnPathComplete);
}

public void OnPathComplete(Path p)
{
    Debug.Log("Yey, we got a path back (error = " + p.error + ")\n");
    if(!p.error)
    {
        path = p;

        // Reset the waypoint counter
        currentWaypoint = 0;
    }
}

protected void SetupAgentLocomotion()
{
    if(path == null)
    {
        locomotion.Do(0, 0);
    }
    else
    {
        // Direction to the next waypoint
        Vector3 desiredVelocity = (path.vectorPath[currentWaypoint] - transform.position).normalized;

        // Check if we are close enough to the next waypoint
        // If we are, proceed to follow the next waypoint
        if(Vector3.Distance(transform.position, path.vectorPath[currentWaypoint]) < nextWaypointDistance)
        {
            currentWaypoint++;
            if(currentWaypoint < path.vectorPath.Count)
            {
                Debug.Log("Move to next waypoint : " + currentWaypoint + "\n");
            }
            else
            {
                Debug.Log("End Of Path Reached\n");
                path = null;
            }

        }

        desiredVelocity *= speed;

        Vector3 velocity = Quaternion.Inverse(transform.rotation) * desiredVelocity; // desiredVelocity

        float angle = Mathf.Atan2(velocity.x, velocity.z) * 180.0f / 3.14159f;

        locomotion.Do(speed, angle);
    }
}

void OnAnimatorMove()
{
    transform.Translate(animator.deltaPosition, Space.World);
    transform.rotation = animator.rootRotation;
}

// Update is called once per frame
void Update()
{
    SetupAgentLocomotion();
}

I then tried to simply order the unit to the player position, but the ai just walks right through all the obstacles, into my direction and keeps walking straight ahead outside the grid. Is there anything wrong with the script? Or does anyone else have a working class for mecanim agents? That would be a huge help!

Did you find any solution yet? I’m trying basically the same :slight_smile: