- Home /
Navmeshagent fails to calculate path. Useless!
Hi guys,
i have hit a major snag with the unity navmeshagents. i have a 2km by 2km terrain with mountains etc. i have baked a mesh, the agents are spawned at start(). only one agent is calculating the paths, the rest just stay there idle.
what are the limitations of navmeshagents? im using unity pro 4.0.0f. i use the same prefabs(navagents) on a smaller map and everything works... what is the solution or alternative to the navmeshagents. i tried other solutions i found like setting stoppingDistance=0; it still fails.
without pathfinding? my game is useless....
please advise. any other alternatives to navmesh...?
function Start () {
var ind:int=Random.Range(0,capturePoints.length);
var avoidancePriority:int=Random.RandomRange(70,90);
canShootRange=Random.RandomRange(20.0,50.0);
h_renderer=h_renderer_obj.GetComponent(SkinnedMeshRenderer);
g_renderer=g_renderer_obj.GetComponent(MeshRenderer);
navagent=Instantiate(navagent_prefab,transform.position,transform.rotation);
navagentcomponent=navagent.GetComponent(NavMeshAgent);
navagentcomponent.avoidancePriority = avoidancePriority;
navagentcomponent.speed=Random.RandomRange(3.5,4.5);
navagentcomponent.stoppingDistance=0;//Random.RandomRange(1.0,10.0);
curDest = capturePoints[ind].transform.position;
navagentcomponent.SetDestination(curDest);
anim_controller.SetFloat("RunSpeed",0);
anim_controller.SetLayerWeight(1,1);
}
private var followDist:float;
private var MAX_MOVE_DISTANCE:float=50.0f;
private var isShooting:boolean=false;
function FixedUpdate () {
if (navagentcomponent.active)
{
Debug.Log(gameObject.name+" :: "+navagentcomponent.hasPath);
Debug.Log(gameObject.name+" :: remainingDistnce: "+navagentcomponent.remainingDistance);
var moveDistance:float = MAX_MOVE_DISTANCE * Time.deltaTime;
var source:Vector3 = transform.position;
var target:Vector3 = navagent.transform.position;
var seekVelocity = Seek(source, target);
seekVelocity = ClampMagnitude(seekVelocity,moveDistance);
followDist=(navagent.transform.position-transform.position).magnitude;
followDist=Mathf.Clamp(followDist,0,1);
anim_controller.SetFloat("RunSpeed",followDist);
rigidbody.AddForce( seekVelocity, ForceMode.VelocityChange );
//navagent.transform.LookAt(curDest);
if (!isShooting) transform.LookAt(navagent.transform);
}
}
alt text
Please post the code you have so far. A picture of relevant data from the scene might also increase your chance of getting a good answer.