Thursday 4 February 2016

AI & Basic Combat Animation

I set up a small scene in which I wanted to experiment with third person combat and I wanted to share it here to see what you think. I used the same model and animations I've been using for my 3D tutorials, found here, some animations from the standard assets of course and some very cool take down animations which I got here.

The scene is really simple, here is only one enemy patrolling the small area and you can choose to activate or deactivate his sight and hearing, so you can see the AI in action..or not.

I could make a tutorial, with scripts and pictures about it but it would take a ridiculous amount of words and time, however, I will make tutorials for some of the features of this small project, like state machine for artificial intelligence, avatar mask and maybe some shader stuff.

I took advantage of the power of inheritance to write the states of the enemy, you know, patrolling, chasing, searching ecc, that allowed for a quick mapping and programming of each state and transition between one another. The enemy will be able to hear you running and walking and will come and check where the noise comes from, going back to patrolling the area if he doesn't see you. If he does, well, he will just start chasing you and shoot you like mad.

Bot characters use similar animators, however the enemy is driven by a NavMeshAgent component and the animation parameters are changed according to the state the enemy is in: for example, while patrolling I feed a lower value for speed to the animator, so the blend tree will play the walking animation, while when the enemy is chasing you, he will be running.

It is not perfect yet, it tends to rotate weirdly occasionally, and he shader is also misbehaving, a couple of things I have to look into.

The player has pretty standard moving mechanics, I also tried to implement a basic "combat system", which is not a system at all: when the player is behind the enemy and close enough, if they are facing roughly in the same direction the enemy's shader will highlight the enemy's model, signalling to the player that it is in range for an attack. If you left click at that point, the player and the enemy will be set into position and the combat animations will play. It was my first attempt to combat mechanics and I dare to say I'm quiet happy about it.

The scene can be played here.

No comments:

Post a Comment