My plan for this second weekend on exploration in Unity3d : Give’m goblins some behavior !

Last weekend I basically had a plane with some Goblins standing statically around doing their best imitation of a sitting duck and looking funny at you. As a player we could could walk around and toss fireballs at them. But hey that’s not much of a challenge now is it ?

Time to add some life to them. The first thing I wanted to give the Goblins was some way of moving around. It would be nice if they could wander around and even better, to walk a patrol route ! So after messing around with some animation code, dumping some gameObjects as patrol nodes, etc, they where able to walk a patrol…..as long as nothing was in their way ! I would need to give them a sense of their surrounding to get around obstacles between their path. Pathfinding it is then.

In the asset store I found exactly what I was looking for : Simple Path by Alex Kring. After watching the video and reading the documentation I started with the implementation of it. This could not be simpler ! In no time I had my Goblins wandering around and patrolling all over the place 🙂 In the demo’s that came with the plugin i found that you could even let objects chase an other one. Perfect !

Looking at the scene now shows a bit more life. Though the goblins now are horrible failing at playing sitting ducks, we as a player have a bit of a harder time to shoot them down with our fireballs 🙂

Next up :

Give the patrolling and wandering goblins something to look for, obviously the Player for now. I looked for a Field of View tool in the Asset Store and … was pleasantly surprised with : Fov Mesh Maker by Hyungseok Seo. The documentation is quite hard to read, but the author did his utmost best to write it in English. The examples provided with the plugin are quite well and gives you all the information that you need to work with it.

After messing around a bit we now have some goblins with vision ! I guess before they had some freaky third eye or where psychic. Either way, now they can actually see where they are going 🙂

By now the scene evolved to a bunch of goblins that are roaming around, patrolling and looking for the Player. If they spot the player, they start casing him for ever and ever more.

Evolve the scene and add some gameplay !

I tried to make the scene a bit more interesting by adding a room in the middle of it. Due to the placement of the room we have an outer ring that we will now call “corridor”. The room has one entrance and in the room I put a cylinder with a glowing golden ball. This is what the goblins will try to protect.

With these elements in place we can now work on more behavior code : The player has to avoid detection by the patrolling goblin in the corridor. sneak into the room and get to the golden ball without being detected. If one of the goblins in the room spots the player, he should run for the alarm gong and rouse all other guards in the room so they can join him in chasing the player.

Building the Alert mechanism was quite fun indeed 🙂 On google i searched for a free 3d model of a chinese gong that could function as a nice prob. After a bit of searching around I found a really nice 3d studio model. Upon importing the model my scene grinded to a halt. The model has _so many_ polygons that basically the GPU turned nuclear 🙂 I either had to look for a low polygon one or somehow fix this one. Searching google for this problem i found a solution \o/

I should be reducing the amount of polygons the object. To accomplish this I used MeshLab. Now the model was nice at 7500 tris ! Awesome stuff we have an alert gong prob standing ready for a goblin to bang his head against , or _if_ its smart enough he’ll use one of his brethren as a battle ram 😀

Binding the guards to the alert Gong should help us in the level building. Basically you would like to just drop in the alert gong and your prefab guards should be automatically registered. To accomplish this I added a boolean to the goblin prefabs isGuard. The gong would have a big collision box on it that is setup to act as a trigger. Now make the box as big as the area you want to alert gong to cover. Any guard in the collission box will be registered by the alarm. When a guard sees the player he will make a run for the gong and sound the alarm ! The alarm prob monitors if it is sounding and if so it will send a message to all the registered guards to start chasing the player.

With all this in place we had some basic gameplay mechanics and the clock stroke 01:00 sunday night…. Quite happy with the progress i could finally head to bed and have some well deserved sleep , finally ! (i can never sleep well when working on stuff so friday and saterday night the sleep did not come…)

You can View the progress of last weekend just to get an idea of the state i was at before i stared to continue this weekend.

And here you can view the results of this weekend !

(use 1 to shoot a fireball !)