January 20, 2014
While working on my project, I've looked at Mecanim for the animation of my AI agents.
Here is my first try at using Mecanim with
Aron Granberg A* Pathfinding Project.
step 1 : Take the "Nav Mesh Example" scene from Unity
Mecanim Example Scenes.
step 2 : Import the free version of
Aron Granberg A* Pathfinding
in the project, and add a A* Pathfinding graph. For my test, I've used the 3.4.0.5 version, and I've
added a GridGraph of 160 x 120 with a node size of 0.4 and with a center at 0;0;0.
step 3 : Create a script named
AgentAStar.cs with the code linked.
step 4 : Modify the TeddyBear object from the scene. Remove the Agent script and the NavMeshAgent component.
Add the Seeker and the SimpleSmoothModifier scripts from A* project and add the AgentAStar script described above.
It should look like that:
step 5: It's done! Run the scene and left click on the ground to move the bear.
Possible improvements:
- Add all Crates in an obstacle layer and mask it in the graph
- Tweak modifiers, node size, erosion ...etc.
- If you own the Pro version, you can use a recast Graph for better results.
If you have a better implementation or a different working code, feel free to post it on the official
A* pathFinding forum.