Tuesday, April 19, 2011

Huzzah!

Prior to my beta review, I had been struggling to understand how the agent behavior tree would direct changes in the agent's path.  Feedback from my beta review helped to clarify this.  The behavior tree will simply change the edge weights in the graph representation of the world.  My agent will recalculate its path every frame to react to these weight changes.

The first step in implementing this design is to have my agent recalculate its path every frame.  At first, I ran into some memory issues.. eek.


I resolved this by revising my pathfinder code.  Instead of returning the entire path, the pathfinder function now only returns the next node in the path.  This is sufficient since the path will be recalculated every frame (so returning the entire path is excessive).  Out of memory error fixed.

I still had to tackle my bug from my previous post, where the agent would stop before arriving at the target.  I identified the bug in my graph representation, where I was handling obstacle corners incorrectly.  I was creating a diagonal edge around a corner when I shouldn't have.  I fixed this bug, and huzzah!  See the video to watch my agent arrive at its target location.  (Again, the non-smooth movement is an issue with the recording's frame rate.)

Sunday, April 17, 2011

Path Following!

Can finally see the agent following the path calculated by A*!  The frame rate of the recording isn't great, but imagine the agent moving smoothly :)

One more bug: The agent is stopping before it arrives at the target, which is indicated by the small pink square.

Thursday, April 14, 2011

Unity Woes

I have been having trouble understanding how access of variables between scripts works in Unity.  I thought I knew how, but after much trial and error, I am still getting errors.  My pathfinding code is contained in one script, and my agent behavior code is contained in another.  Because of this obstacle, I have been unable to have my agent respond to the path calculated by my pathfinding code.

For example, in the screenshot below, the console shows a path count and the index.  I want the index to initialize to 1 less than the path count, which it currently is not doing.


I have already read a lot of Unity manuals and tutorials, but I suppose I need to read some more...

Saturday, April 9, 2011

Some Videos

The first video shows my project implementing the Roomba behavior tree.


The second video shows in the Unity console that my project correctly creates a graph representation of the world and calculates a path from a starting to end node. The position of these nodes and the edge costs are specified in the bottom right corner.

Thursday, April 7, 2011

A* and Unity

This week I had my beta review with Joe and Professor Badler. The review was extremely helpful in confirming my approach thus far and in generating ideas for how to get past some of the road blocks I am facing. Another point of feedback was to post to my blog more frequently -- even if I do not have a result to show, it's important to share and discuss the problems I am trying to work through.

At my beta review, I showed my progress since the alpha review:
- A* pathfinding implemented in C++. I am more familiar with C++ than C#, so I wanted to focus on implementing the logic of the algorithm rather than struggling with syntax.
- Graph creation in Unity. I needed a graph representation of the nodes and their neighbors in Unity before I could implement pathfinding. Each node has 8 neighbors (since my map is a square grid). I spent a lot of time here reading more about Unity and C#.
- A* pathfinding in Unity. I can specify start and end nodes and the code will generate the correct path. I am still trying to understand how Unity's physics engine syntax works, so I am still working to have my agent respond correctly to the paths generated. This will be my major task for the week.

I plan to have my behavior tree dynamically recalculate weights on the graph to influence the paths generated by the A* algorithm. Because I will be making constant calls to A*, I want to go over my code again and try to make it as efficient as possible.

Friday, April 1, 2011

Integration

This week I've been working to integrate my A* code with Unity in preparation for beta reviews.  Still have some polishing to do, videos to come soon!