0
\$\begingroup\$

There are destructible and indestructible objects on the map I created with Tilemap, and I create a walkable area (bake) for my enemy object using the information I found on the internet and the Navmesh packages for 2D games. However, the problem is that after my player destroys breakable objects (Tilemap grid cell), the enemy object still perceives those areas as unwalkable. I'm wondering how I can update the navmesh for the enemy again while the game is running.

I found videos and information on how to do this in 3D games, it looks pretty simple. But I couldn't find anything for 2D games.

Note: I'm using Unity.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ What tools are you using? Engine? Frameworks? \$\endgroup\$
    – Theraot
    Jan 9 at 2:24
  • \$\begingroup\$ I am using Unity. I am not using any Framework. I'm asking because I couldn't find or overlook such a Framework. \$\endgroup\$
    – gunza
    Jan 9 at 4:01
0
\$\begingroup\$

I found a solution. First of all, download the package in the link and put it in unity. (required for 2D games)

https://github.com/h8man/NavMeshPlus

Then you can follow how to do it from the link below: (Do what is explained up to the GEOMETRY OPTIONS heading.)

https://github.com/h8man/NavMeshPlus/wiki/HOW-TO

Finally, create a script for your object named "NavMesh" and write the following code. Thus, if your map objects disappear or move during the game, that free space will be recalculated and become a walkable area.

 using UnityEngine;
 using UnityEngine.AI;

 public class Runtime : MonoBehaviour
 {
public NavMeshSurface2d Surface2D;

void LateUpdate()
{
    Surface2D.BuildNavMesh();
}
}

Note: Don't forget to assign the NavMeshSurface2d component to the Runtime script.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .