private void GenerateCrowd() { if (!hasGenerated || navMeshQuery == null) { return; } System.Random rand = new System.Random(); crowd = new Crowd(MAX_AGENTS, 0.6f, ref tiledNavMesh); SVector3 c = new SVector3(10, 0, 0); SVector3 e = new SVector3(5, 5, 5); AgentParams ap = new AgentParams(); ap.Radius = 0.6f; ap.Height = 2.0f; ap.MaxAcceleration = 8.0f; ap.MaxSpeed = 3.5f; ap.CollisionQueryRange = ap.Radius * 12.0f; ap.PathOptimizationRange = ap.Radius * 30.0f; ap.UpdateFlags = new UpdateFlags(); //initialize starting positions for each active agent for (int i = 0; i < numActiveAgents; i++) { //Get the polygon that the starting point is in NavPoint startPt; navMeshQuery.FindNearestPoly(ref c, ref e, out startPt); //Pick a new random point that is within a certain radius of the current point NavPoint newPt; navMeshQuery.FindRandomPointAroundCircle(ref startPt, 1000, out newPt); c = newPt.Position; //Save this random point as the starting position trails[i].Trail = new SVector3[AGENT_MAX_TRAIL]; trails[i].Trail[0] = newPt.Position; trails[i].HTrail = 0; //add this agent to the crowd int idx = crowd.AddAgent(newPt.Position, ap); var targetPt = navMeshQuery.FindNearestPoly(new SVector3() { X = 0, Y = 0, Z = 0 }, new SVector3 { X = 1, Y = 1, Z = 1 }); //Give this agent a target point //NavPoint targetPt; //navMeshQuery.FindRandomPointAroundCircle(ref newPt, 1000, out targetPt); crowd.GetAgent(idx).RequestMoveTarget(targetPt.Polygon, targetPt.Position); trails[i].Trail[AGENT_MAX_TRAIL - 1] = targetPt.Position; } }