DevLog #3 - Bad guy navigation (or not)

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):

  1. [Wandering] If you can't see anything, pick a course and stick to it
  2. [Intercept] If you can see the player "close enough" (some distance) then turn toward the player
  3. If the player goes out of sight, go back to [Wandering]
  4. [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.

Next

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.

Comments

maybe you could have then have other enemies that have patrol routes that they stick to rather than random destinations. I vaguely remember a unity tutorial on how to do that in the base unity tuts think it was pretty simple a bunch of waypoints (using empties) in the game it will move through as a list could even be procedurally generated with not much effort.

Evilmatt's picture

Ah yes, I found that one. I was looking at state machines in Unity and the tanks following way points in a patrol is how she does it. It'll be perfect.

brainwipe's picture