Geometry (NavMesh) collision detection using collideWith()

I am trying to determine whether or not my ray casting is colliding with the NavMesh Geometry created using the SDK Navigation Mesh plugin. If I am not mistaken, the NavMesh generated is a Geometry and collideWith() doesn’t seem to be treating it as a shootable object. Is there a way to make the NavMesh a shootable object to retrieve collision data?

no, also why would you?

1 Like

I am using the pathfinding algorithm from MonkeyZone. It works well if I do something like this but it doesn’t account for locations that are not inside the NavMesh (i.e it still creates a path that is just a straight path from one location to that location):

NavMeshPathfinder pathFinder = new NavMeshPathfinder(navM);
Vector3f targetLocation = pathFinder.warp(moveMark.getWorldTranslation());
pathFinder.setPosition(selectedTarget.getWorldTranslation());
boolean hasPath = pathFinder.computePath(moveMark.getWorldTranslation());

Where navM is the mesh generated using the plugin, and moveMark is the location the player click at using:
moveMark.setLocalTranslation(new Vector3f(closest.getContactPoint().x, 0, closest.getContactPoint().z));

In some NavMesh thread on the forums, Sploreg did something different for the warp (which is suppose to determine if the point is in the NavMesh, but it doesn't work for me - instead of doing computPath on moveMark.getWorldTranslation(), he uses the targetLocation again, but for me, the computePath returns incorrect data.

I tried to figure out how the warp works to no avail, so I decided to try what I described above. Hopefully, Sploreg sees this thread and can give me some insight on this. Or perhaps you normen :D You guys are both great.

The navmesh is built from a base mesh, e.g. a terrain, you should use that for placing the mobs after you got the navigation location from the navmesh.

1 Like

Ok, let me explain from scratch how why I am using a NavMesh. I am using the NavMesh purely to avoid my main unit to collide with structures and props I have in my scene. The only spatial that changes location throughout the run of my game is the “hero” spatial each player has. Everything else is already populated right from the start of the game and will remain at the same location.



As it is right now, the PathFinding algorithm from MonkeyZone does the job - that is, if I want my hero to move to a certain location and there are structure between the current location of my hero and the end location of my movement, the pathfinding algorithm will give me a set of waypoints that define the path that my hero spatial should take in order to avoid touching the structure. The problem is, when my target location is (the place I click on with my mouse when I have my hero spatial selected) is a spot that is not covered by my NavMesh, in this case the structure, the pathfinding algorithm will still create a path to that location and the path will be composed of 1 waypoints, which is the exact spot I clicked on.



So what I am trying to do is to prevent the pathfinding algorithm to generate a path - that is, I want it to realize that the location I clicked on is inside the NavMesh and should reject computation. Like I said before, from a previous post that Sploreg posted (http://hub.jmonkeyengine.org/groups/general-2/forum/topic/mesh-navigation-buildnavigationpath/), he mentions that the .warp(Vector3f) can be used to determine if a particular point is in the NavMesh, but I just don’t understand how to use it.



Also, I don’t know if this is the only way to do it. Perhaps there is a utility method somewhere that can simply help me determine this using a Vector3f (the location that I click on) and a Mesh (which is the NavMesh I extract from the scene)? Thanks for the help normen.

Yeah, navmesh has methods to find the closest cell for a certain location, you just need to check if the location of your character and the target location are in the same cell before asking for a path if you don’t want pathfinding then… NavMesh.findClosestCell()…

1 Like

I am not sure if I understand - My understanding of cells are the triangles composing the mesh. Can’t my character and the target location be on different triangles and it should still be able to compute a path? I think my understanding of cells might be wrong. In any case, I don’t exactly understand how I should be checking if my character is on the same cell as my target location, and why should I be using findClosestCell()? To be able to remap the click to somewhere around my structure (i.e a place that should be accessible on the navmesh). Also, findClosestCell returns a Cell object - how can I use this object to compute the path to the location since NavMeshPathfinder works with Vector3f ?

I thought you meant “I don’t want my char to move when he moves within one cell” cause everything else doesn’t really make sense…? Why are you so dependent on the navmesh when you don’t actually want to use it :? Or the other way round, why would you expect navmesh to work when you work outside of the area its meant for? You can check if the character and/or click is covered by the navmesh… If not, you just do a ray test from above to determine the location you put your character, as I mentioned in the first post… Just interpolate a vector from a to b over time for the x/z coords and do the ray test for the y coordinate.

1 Like



So here is a picture showing what I am trying to do. So suppose at run-time, my character is at the location specified by the letter "H" for Hero. If I select this Hero and then I click on the location specified by "L", computePath() will provide me a set of waypoints that will go around the part of the NavMesh that contains the letter "S" for structure. So what I am saying is that, if I click anywhere on the terrain other than the polygon that contains the structure (i.e the letter "S"), computePath() does the job.

The problem is, if my Hero is at location "H" and I click on anywhere within the polygon that surrounds the structure at location "S" , computePath() still returns a valid path, which is composed of one waypoint that points exactly where I clicked, and my hero walks to the location (right through the structure). What I am trying to do is not allow the user to click within that polygon where the structure "S" is located, or even better, remap his click to somewhere around that polygon (but if I can get the first working, I'm ok with that). To my understanding, that polygon represent non navigable area of the NavMesh.

uh… that navmesh basically says “you can go anywhere”…

1 Like

Really? I was told triangles in a NavMesh indicate navigable terrain and polygons (with >3 sides) indicate places that are not part of the NavMesh. Also, why is it creating a path around that polygon that contains “S” when I click on location “L” and my Hero is at location “H”. Shouldn’t it just create a straight line and pass right through “S” if everything is passable within this NavMesh?



Is there anyway to do what I am trying to do with the things I described to you? Is there a way to generate a NavMesh from the plugin that does what I need? (The way I generated the NavMesh was by placing the models in the scene composer then generating the NavMesh with default setting, and finally removing the models but keeping their coordinates from the scene and then using those coordinates to load them from within the code).



Edit: Here is the a picture of the waypoints generated in game, with the example I explained in the first paragraph. The Structure isn’t exactly where the polygon I am talking about in the NavMesh is, but it is close enough. You can see that the Path create circles around it somewhat.

Hi,



i think your obstacle is to low, so the navmesh generator didnt make a “hole” into the navmehs where your obstacle is.

Play around with the settings in the navmesh generator, like the Min Traversable Height, Max Traversable Step and Slope.

As long as a Polygon is in a navmesh, you’ll be able to navigate there.



Regards

1 Like

You need to change your configurations to change the behavior of your mesh. That mesh means, like @normen said, you can go anywhere. Take a look at those 2 pages:



Overview about navmeshes and other map representations: Map representations

Documentation about the used library (I really recommend reading this page http://www.critterai.org/nmgen_study SPECIALLY THIS PAGE HERE —> http://www.critterai.org/nmgen_config)

1 Like

This is how a proper navmesh would look:



(actually the minimum tile size is a bit too high in this pass, the bridge should also be a path…)

1 Like

@normen Hey, is there any tool int he SDK to manually edit meshes?

No

@normen So, I know how to import lots of formats to j3o, but how do I export a mesh from the a j3o file?

You cannot unless you write your own exporter. j3o is like a compiled class file. paths are absolute and they are meant for one games distribution.

1 Like

@normen @snareoj2 @shirkit Thanks so much for the help and the resources guys, I think I am on the right path now (no pun intended!)

@normen said:
You cannot unless you write your own exporter. j3o is like a compiled class file. paths are absolute and they are meant for one games distribution.


I was generating my Navigation Meshes through the SDK plugin, but now I see that I'll have to use NMGen in separate if I want to manually correct NavMeshs.