playMaker

Author Topic: Navmesh and "Set Property"  (Read 6083 times)

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Navmesh and "Set Property"
« on: August 10, 2013, 12:03:22 PM »
Okay, setting up your NavMesh isn't hard and getting it threaded into a system isn't hard either.

Please note that this is using Playmaker version 1.7.0f5 and Unity3D 4.2.0f4. I am unsure if these methods will work with an older version of Playmaker so if you haven't updated, it might be time to consider it.

If you need some help setting up NavMesh, here's the process i followed.

Step one... have the scene where you want the NavMesh navigating around. to do this follow these steps.

NOTE: this is a very, very basic process... there are more nuances to this system but so far i've only gotten to the point of getting the most basic functionality set up.

1. open the Navigation tab from the "Window" menu.

2. Have the level you want to navigate set to static (it's that little check-box in the top-right corner of the inspector.) you don't need to set it as static in all features, you can simply click on that down arrow and select "Navigation Static." Do this will all objects that you wish to use for this system (Walls, Trees, Rocks, etc.)

3. Once you have all the objects you wish to use in the generation of your Navigation mesh, in the Navigation tab there should be three tabs/buttons at the top... "Object," "Bake" and "Layers." Go to the "Bake" tab/button.

4. Set your radius and height as well as the maximum slope and step heights (so if you have slopes or stairs you want your NavMesh agent to use, set these parameters appropriately.) Since i'm using the Indie version of Unity, the advanced options such as drop-height and jump distance are greyed out but for what I need this is not necessary. once you have that all set up, you can click "Bake" at the bottom right of that tab and it will generate your NavMesh.

4a. The Radius in the "Bake" tab seems to have the radius of how far away you want your navmesh to create from walls or corners or things like that... this seems to be in the standard Unity units of measurement so one unit roughly translates to (essentially) one meter. EDIT: Please note, however, that when the navmesh system calculates the path, it's essentially just a line that it's drawing... so, if you have the radius as hugging the walls too tightly you could have the unintended result of having enemies or other agents getting caught on corners because the path that they have been routed to follow will result in them clipping the corners or other angles like that. So, try and find a good value for this that's neither too far away or too close. if you have a somewhat standardized size for your enemies, try and make the radius value be half of how wide the character is... so, the radius on the navmesh component and the radius of the walls themselves matching would probably be a good place to start.

4b. The Height field is how far above the area you want your navmesh to be generated. I've done some testing and this appears to be the place where the feet would touch the ground for the entity that will be using this... so, if you put in a large value that makes it appear as if the NavMesh is half a meter above the ground, the entity will think that that is where it's feet will be colliding with the floor so try and keep this value as close to your mesh object if you want it to look like your agent is using the floor. This is part and parcel with the navigation agent since that controls things like gravity (so, no rigid bodies needed to have gravity it appears.) This is also more just with the little bit of experimentation that i've managed to use. I'll know more as I learn more and I will update this thread with the pertinent information as I learn it.

5. For this exercise, just create a new cube and name it "NavMesh Enemy" make sure that it is placed above where your NavMesh is generated as i suspect that if it passes through it, it might fall through (though i'll know more about this as i learn more.)

6. with the new enemy highlighted, go into the "Component" menu and select "Navigation" then "Nav Mesh Agent." This will add in the driver which will control things like movement, collider height (well, the NavMesh collider... i'll play around with this later today) Speed, acceleration, angular speed (how fast it turns) and even stopping distance (do you want it to stop when it's half a meter away? do you want it to keep pushing regardless?) There are additional features in there that I have yet to explore but for now just set them as you want them to... Note, the collider that the navmesh agent uses is a cylinder... I have not found a way to change that to something else...

7. Now that you've got that, with the Enemy highlighted, add a new FSM in there. This part is very easy to do... you can customize this to your own purposes but understand that this is only the bridge to transfer information in there... so, once you feed it information, the NavMesh Agent will do the rest (so, be aware of that for your own purposes.)

8. In the first state, put in two actions in this order... "Get Position" and "Set Property." If you have a Player character in there already, you're on your way... if not, just whip up a really quick third-person controller (there are tutorials on how to do that linked on the Wiki.) In the variables tab, add in a Vector3 variable and name it however you like (i used "Location.")

9. Now that you've got that, make the "Get position" action find the location of the player character you want the NavMesh agent to follow. store that in the Location variable and make this in World space and execute every frame.

10. in the "Set Property" action, with the inspector and graph-view visible, drag and drop the "Nav Mesh Agent" component from the inspector into the "Target Object" Field. you should now see the "Object Type" field with a greyed out "UnityEngine.NavMeshAgent" in there and a drop-down available.

11. In the drop down on the "Set Property" action, look for the "Destination" sub folder and in there choose the "Vector3" option. now change the vector3 field that should now be there to use the variable (I used "Location") you have extracted with the "Get Position" action and tell this action to also execute every frame.

Now you've got the most basic system in place... click run and the agent should pursue your player character and take advantage of the navmesh to navigate around it.

A few things to keep in mind. Though this doesn't need the Rigid body to be affected by the nav-mesh, you will need to have some way of ensuring that this object is not intangible (unless you want it to be.) So, I added a regular Rigid-body to give it the mass it would need to not just pass through the player however I turned off the "use gravity" since the NavMesh component already has this handled for you. I have encountered no issues with using these two together but that's not to say that there simply won't be (like i said above, i'm still learning the nuances of this system.)

This is all done with an indie version of Unity3D so you should now have the basic means of getting NavMesh into your games... and this is the absolute, most basic way i've found of having these systems work together... take your own FSMs and make them even more interesting.

Let me know if you have any issues or would like some assistance... If i can I will give it my best.
« Last Edit: August 10, 2013, 01:13:29 PM by Red »

Red

  • Hero Member
  • *****
  • Posts: 563
    • View Profile
Re: Navmesh and "Set Property"
« Reply #1 on: August 10, 2013, 12:46:02 PM »
I've figured out that with regards to the "Height" on the navigation tab in the Bake sub-tab, if it is intersecting with the entity you want it to drive, it won't pass through...it seems that it will revert to that height... so, this begs the question, will gravity work with these objects? maybe, maybe not... i'll have to push this one through the grinder as I go to figure out more.

So, to clarify... the height is where your character will have their feet at the ground... It does seem to have it's limits though so if you have it far above or below to the point where it's not connecting (or possibly within a certain range) it's just going to ignore the navmesh.