The next step in Cloudship is adding bad guys that will follow eventually hunt and kill the player. I know that I'm going to create a finite state machine eventually where the enemy will sit at various states and move from one to the next given certain times. The machine will be made up of rules like this ([name] rule):
- [Wandering] If you can't see anything, pick a course and stick to it
- [Intercept] If you can see the player "close enough" (some distance) then turn toward the player
- If the player goes out of sight, go back to [Wandering]
- [Shooting] If the player is very close, slow down and start firing.
And so on, that's enough for now.
Unity's inbuilt navigation
So I decided that a good place to begin is by using the inbuilt Unity3D navigation system. It's quite cool, you assign a navigation agent to your game object (a pill shaped bad guy at the moment) and then give it parameters about how fast it should move, turn and how big it is. You then press a button "bake" your complex mesh environment to a simple set of triangles for the path finding to work against. Bingo!
I did all that but the bugger wouldn't move. I watched a bunch more and had a fiddle with parameters (largely blindly but easy to do).
Then it occurred to me: I don't have an environment to bake! I think the Navigation component is great, but it works with more classic environments, which I don't have.
Fortunately, I built the environment by moving the force calculation out of the Cloudship player into its own objects. Hopefully this means that I can reused the same methods for the bad guys. Not sure what sort of finite state machine C# pattern I'll use. I think I'm going to use a fluent built one.