Hi all, I have a problem with AI. I am thinking about it for a long time.. but I cant figure it out.. So, I am using Unity nav mesh pathfinding for my mobs/enemies. The avoidance between mobs works quite good. But if there are many mobs, they are trying to find the shortest path to the player. Few mobs reached the player, but other mobs are stucked. They should find another way, around other mobs.. This is my actual behavior: How mobs should go to the player: Does someone have any idea, how to fix it? Thanks for your help!
Perhaps, instead of having them move right towards the player, you could have the agents move to positions slightly off to the sides first, and then have them move from there to the player.
Hi, I am using this method: I am using navmesh pathfinding for player, and enemies. (agents).. if enemies are chasing player, there is navmesh agent enabled. (and navmesh obstacle disabled). And if are mobs attacking, there is navmesh obstacle enabled. (agent disabled).. They are not active in the same time/frame! But, i want to use carving.. Navmesh obstacle -> carve. After enabling the navmesh obstacle (and disabling agent) my player starts to move to the "spawn" position.. (and other agents too).. I can not explain this behavior, why are they moving... Without carve feature, all agents stay in own position. Could someone help me please?
Hi, I just disabled all navmeshagents, when the player/mob does not move... But I have a new problem.. again When the agent starts to move (chasing the player for example), there are moments when the agent ist dragged back. You can see it in the video below. I don't know, if I am wrong, or it is a weird bug.
If you want the mob to surround the player, don't use carving, instead give each mob a different destination around the player.
I use this in turn-based game now. The sequence is that: 1.disable carve 2. wait for NavMesh.SamplePosition on your position returning true while(!NavMesh.SamplePosition(GetCurrPlayer().transform.position, out hit, 0.2f, NavMesh.AllAreas)) { yield return new WaitForEndOfFrame(); } 3. Then enable navmeshAgent and start your move! NavMesh need some time to recalculate itself when you enable/disable carving. When you put your navMeshAgent enabled and don't have navmesh under agent (becouse it is not recalculated) it moves to the nearest navmesh. Whole code looks like that: Code (CSharp): GetCurrPlayer().transform.FindChild("NavMeshObs").GetComponent<NavMeshObstacle>().enabled = false; GameManager.instance.StartCoroutine(lateNavMeshAgentEnable()); ... static IEnumerator lateNavMeshAgentEnable() { NavMeshHit hit; while(!NavMesh.SamplePosition(GetCurrPlayer().transform.position, out hit, 0.2f, NavMesh.AllAreas)) { yield return new WaitForEndOfFrame(); } GetCurrPlayer().GetComponent<NavMeshAgent>().enabled = true; GetCurrPlayer().TurnStart(); } Maybe it will be too long for some FPS, but it is OK for TBS game. The other thing i'm mesing with right now, is that SOMETIMES navMesh is broken after recalculating with that carving AI and i have breaked plane in too picies and players can go through an "invisible navMesh wall" in the middle of the room. Don't have any decision about it.