2D navigation with Unity can be painful
I'm currently ploughing through a code refactor, converting some quite old code to use better encapsulation, inheritance, polymorphism (OOP basically) and fold in newer code from another, similar project. This will be ongoing for some time. I also struggled with NPC navigation this week. The last time I tried this game in 2D I gave up because Unity doesn't support navmeshes in 2D, only in 3D, and the third party tool I used worked really well but didn't scale up to the number of objects I wanted in the world if I wanted them to be movable. That's when I converted to 3D, which just made my life a lot harder in other ways. I've broken through that barrier now (quite messily) and assuming the solution continues to scale and function properly, I can move on to other things and come back later to clean up as part of the AI refactor.
My specific issue with navigation was performance. Using PolyNav, I had a great pathfinding and navigation system going but I found that updating the position of obstacles dynamically was causing a lot of stuttering in game once I went past a handful of them. When I queried the developer of PolyNav he confirmed that the solution wasn't meant to scale up and track that many dynamic obstacles. This is the exact issue I ran into last time and Unity navmeshes only work with 3D (properly). The breakthrough came when I started testing NavMeshPlus, basically an extension on top of the built in Unity mesh system allowing it to be used in 2D. It took quite a bit of playing around to get everything "working", but the end result is spectacularly better performance.
As I mentioned at the top, my implementation is a bit of a hack and will need to be cleaned up in a future refactor of the AI, but it feels like I've cleared a very sizable hurdle and am free to continue with space RPG in the form I envisioned it whereas in the past I had to give up on 2D and try it in 3D.
Get Space RPG
Space RPG
An RPG, in space
Status | In development |
Author | gavor |
Genre | Role Playing |
Languages | English |
More posts
- A long awaited return - Movement and partyMay 09, 2023
- Weekly Build available - 25 Apr 22Apr 25, 2022
- Weekly Build availableApr 16, 2022
- Progress - Week 2Apr 15, 2022
- Back to workApr 08, 2022
Leave a comment
Log in with itch.io to leave a comment.