News › Forums › RAIN › General Discussion and Troubleshooting › Terrain navmesh - AI paths through buildings
Tagged: buildings, navigation mesh, Terrain
This topic contains 5 replies, has 2 voices, and was last updated by Sigil 5 months, 3 weeks ago.
-
AuthorPosts
-
February 10, 2022 at 2:51 pm #40036
Hey, beginner question time. I’m quite sure someone else has had this issue but I couldn’t find a search function in the forums so here we are.
So, I’ve got a procedural terrain and I slap some buildings on it. Terrain’s layer is “Terrain” and buildings belong to layer “LevelGeometry”. In the NavMesh parameters I include only the “Terrain” layer. I then put some basic AI blobs to walk around the terrain by giving them random waypoints. Just to get a feel of how things should work.
Now for some reason, very often the AI gets stuck. The reason for this seems to be that sometimes the paths go through buildings. I’ve tried changing the navmesh grid size, cell size, max segment length etc and while sometimes things work a bit better, the core problem never goes away.
Here’s a link to a screenshot of one problem case. AI is stuck humping the wall, because the path goes through the building.
Would the problem be that the buildings don’t necessarily have floors, or if they do they might intersect the terrain?
February 10, 2022 at 3:54 pm #40041You’ll want the navigation mesh to include both the terrain and the building layers. They would also need colliders on them as well, which is what we use for our navigation mesh when calculating walkable areas.
February 10, 2022 at 5:11 pm #40043Thanks for the quick reply!
Unfortunately that doesn’t seem to solve the problem. I forgot to say I have tried all sorts of combinations of layers. The buildings have collisions, so does the terrain. And it seems like they don’t ALWAYS path through buildings.
February 10, 2022 at 5:40 pm #40044Well, let’s step back a second and start over.
Use a default navigation mesh, don’t change anything other than the size of it (either by scaling or increasing the size attribute). Make sure it surrounds the terrain and the buildings you care about (start small so you don’t have to wait so long while testing). Generate the navigation mesh and when it is done take a look at what it looks like, it should only be drawing where you intend AI to walk.
Take a screenshot of it and link it if you can, I’d like to see what it looks like.
February 11, 2022 at 6:05 am #40046Well I’ll be.
For some reason now the nav mesh generates just fine. Previously it completely ignored the buildings. I diffed the changes between what I have now and what I had previously and the only change is that I had navmesh size set to 100 and now it starts off at 10. 100 is the size of my terrain, and I actually set it to 100 at runtime before generating the navmesh…
So it definitely works now, but why is somewhat of a mystery
February 15, 2022 at 11:39 pm #40074Sorry, took me awhile to get back, just thought I mention there are a couple issues when generating at runtime to watch out for. First one is that we deserialize our RAIN components in the Awake call, so you it could overwrite your changes if you try to change the value in an Awake call.
Second thing, there is a bug when you create any RAIN component at runtime where any values changed immediately after creation get lost if you don’t call Serialize the component (NavMeshRig, AIRig, EntityRig, etc). When I looked into it I thought it was only affecting components that are created at runtime, but it is possible it may affect some that are modified as well.
Could be either of those that was causing your problem. The bug is fixed in the next version, but you can work around it by calling Serialize after any runtime changes.
-
AuthorPosts
You must be logged in to reply to this topic.