Hey Guys!! I just payed for my A* Pro tools… and I have started having a small issue with the Recast grid~
My seeker is … not making sense… and seems to be walking in the middle of all the Navmesh lines??
Here is a Image of it~
If you have any idea what the error is, it would help my sanity SO MUCH… Also if you have working seeker code for Navmesh’s or Recastgrids (Seeing as there almost the same thing) that would help a lot too!
And my code (Without turning and … some other stuff) is
``` ` using UnityEngine; using System.Collections; using System.Collections.Generic; using Pathfinding;` ```public class MoveWtihPath: MonoBehaviour {
public CharacterController MyCharacterController; //Var for This-> CharacterController public Path MyPath; public Transform TargetPosition; // Where is the next *macro* waypoint, or end of path, is public Vector3 CurentTarget; // This is where my unit is going right now: public int NextGridSpace;// This is the waypoint in the pathing grid public float UnitSpeed = 8f; public float Smoothing = .6f;// Lets the unit skip to the next Grid Waypoint when at this distance private Seeker seeker; public void Start () { seeker = GetComponent<Seeker>();//Gets Seeker Component off of this object seeker.StartPath (transform.position, TargetPosition.position, OnPathComplete);//Makes a path MyCharacterController = GetComponent<CharacterController>();//Gets CharacterController on this Gameobject CurentTarget = TargetPosition.position; } public void OnPathComplete (Path p) { if (!p.error){ MyPath = p; NextGridSpace = 0 } } else { Debug.Log (p.error); } } public void FixedUpdate() { //---------------State-------------------// // If we have no path to take, return if (MyPath == null){ return; } if (TargetPosition.position != CurentTarget){ seeker.StartPath (transform.position, TargetPosition.position, OnPathComplete);//Makes a path CurentTarget = TargetPosition.position; } // Lower Smoothing so you end on the final waypoint if (NextGridSpace >= (MyPath.vectorPath.Count-1)){ Smoothing = 0.1f; } if (NextGridSpace >= MyPath.vectorPath.Count){ //If where I am now is the end of the path...Reset Smooting, and Return (And add *Move to next waypoint* later) Smoothing = .6f; Debug.Log("End Of Path"); return; } //---------------State-------------------// //--------------Moving-------------------// // The direction to the next waypoint -- -- Normalize makes the Vector (IE: 0,0,50) all in values of 1 -- * our speed Vector3 Direction = (MyPath.vectorPath[NextGridSpace]-transform.position).normalized * UnitSpeed * Time.fixedDeltaTime; //Moves Unit to the next waypoint on the grid! MyCharacterController.Move(Direction); //--------------Moving-------------------// //---------------------Turning-----------------------// *Removed for easier reading* //---------------------Turning-----------------------// //--------Move to next waypoint when done-----------// //If we are at the point (NextGridSpace) .... Go the next gridspace on the list. if (Vector3.Distance(transform.position, MyPath.vectorPath[NextGridSpace]) <= Smoothing ){ NextGridSpace++; } //--------Move to next waypoint when done-----------// }
}