Wednesday, 21 August 2013

Wednesday State Power

I Made The Right Decision

Remember that fateful decision to hack in the ladders, and then my second decision to write an editor for the crouch animations and my day today was to finish that and add more animations to it form the main AI prototype. Well it turns out the 'other' animations required where equally 'interesting' and the editor plus state engine sub-system thingies worked amazingly perfectly, and probably saved me hours of frustration too!

Character Enjoying A Quick Roll

My prototype can make the character relax, stand at arms, crouch, move in different directions, roll to a crouch, roll back to his feet, leap over invisible sandbags, fidget in stood and crouch positions and lots more things I have forgotten for now. The bonus is that it all does this with perfect transitions from state to state which means no glaring switches of animation and ruining the smooth flow of the characters through the game.

Alas I got carried away and it's now 4AM (again) but I found time to clean up the routines part way through my additions which means it's now a separate module that can drop into the AI proto which will happen tommorow now. This system will replace the hacked animation code currently in there, minus the ladders which I dare not touch lest it suck me into four more days :)  I am pretty much decided to use my new sub-system on ladders and stairs as well, but I want to finish animated combat to get back on schedule somewhat.

The Trinity Of AI

As I walked the dog earlier today I got to thinking about blogging the nuance of the Reloaded AI system, and the trinity which will make it all realistic. The first level is Paul's AI bots, which in their robotic style move to locations, rotate to and track down targets, work out cover positions and firing patterns. Imagine this as the 'brain' of your enemy, thinking where they should go and what they should shoot at.

The second level is the new animation sub-system which handles how the 'real character' animates and moves to create smooth transitions between each of these states.  The states of course provided by the AI bot, but thanks to the smoothing techniques of the sub-system the 'real' object trails behind the AI bot a fraction. This gives the impression the enemy knows what they are 'going' to do, and subtle visual clues are evident in the sub-system transitions (such as the head-turn you saw in a previous video).

The third and final level is the wonderful details in the animation itself, thanks to Mark. Each animation brings out human traits like swatting a fly away from a face, looking around cautiously and shifting his weight when standing still for too long.

Combined together, they form a potent enemy, that would look real, move around the scene in a realistic manner and appear to think for real too.  You could say it's a perfect solution for our REAL-OADED product! [shudder -Ed]

Signing Off

Any video today would be a bit random and drawn out as there are a LOT of animations coded now but it really would not reveal any more of the tech background than you have already seen. I think the next good video is when all these animation states and transitions are tied to the AI bot and demonstrating a semblance of combat.

Tuesday, 20 August 2013

Tuesday Second Chances

Combat Day

Starting as a meant to proceed, I deliberately avoided taking the enemy character up the ladders or stairs (except to test the staircase fix from Paul which worked a treat by the way) so I could dedicate today to combat.

I re-activated my direct fire code, blended it into the character states between Petrol and Aggressiveness and then enjoyed the first glimpse of the enemy chasing me malevolently slowly around the small test area. When I lost him, he would switch to casual walk and went on Patrol. All good.

I then added some ducking code so the enemy could take advantage of hiding behind sandbags, and when I introduced my code to play the animation I physically cringed!

How To Duck

This was a lesson you probably learned at school, and if you went to my school you learned it very quickly! Turns out just setting the character to 'crawl mode' does not cut it. Mainly because crawl mode does not exist, I have to write it!  The crouch walk animations which I have my prototype actually included both crouch step forward and crouch step backward, and they included their own movement shift too.  The result was somewhat laughable.

There I was faced with the same dilemma again, whether to hack in a nice duck transition with crouch logic and control the animation in code, or sit back and do something sensible like write an editor and sub-system which could play back what I needed from all things crouch-like.

Here is an idea what you ACTUALLY need to do for a simple crouch mode:

1. Transition through interpolation from CURRENT animation to STAND posture
2. Use the STAND TO CROUCH animation as interpolating to a crouch is yuck
3. Transition to a CROUCH IDLE animation, and loop that animation
4. If MOVE, transition to the first frame of CROUCH MOVE
5. Play a single sequence of CROUCH MOVE and detect the end
6. Once at the end, move the actual character to a new position and reset
7. Repeat step [5] if character needs to move some more
8. If no more movement required, return to step [3] via transition
9. From CROUCH IDLE, if press to stand back up, transition to STAND UP
10. Play through CROUCH TO STOOD animation until detect end of animation
11. Return control back to main character system now out of crouch mode

Now that's just the simple version as crouch can do MANY more things eventually, and the transitions can get freaky when you are dealing with half animations, reverse animations and who knows what else.  You can see the appeal of a code hack!

From my very recent experience with ladders, I did not fancy doing a state machine hack this time so I decided to write a 'State Machine Database Editor and Previewer'.

State Machine Database Editor and Previewer

I won't show you the editor as it's bone ugly, but I will show you a preview from the 'player' which attaches to the editor to show me what I created today.


In the above shot you are looking at the steps I described coded as a sequence of instructions into the dynamic state machine. Think of it as a programming language within two larger programming languages, and ideal for tweaking and changing my mind in terms of order without some serious rewriting.  Also think of it as generic enough to allow me to do other types of character activity that deals with animations, transitions, moving position in tandem with some complex sequence, e.t.c.

The editor part allows me to play through the animation frames, move the object in relation to the floor grid, line up an animation loop exactly with the position advances built into the animation.  It's also a pretty small sub-prototype so I can add things quickly in the future should I decide to return to the ladder system and replace it with this.

What About Combat?

As I predicted, such an effort takes a good deal of time and it's now 2:30AM with no time left to return to combat coding.  What I do have however is the makings of a sub-system that can plug into the character animation system and pretty much handle my crouch behavior within an hour of integration.  

Rather than 'settle' for sliding about and taking a piggyback on excellent animation, this new system will transition in and out of crouch, cover the ground realistically, and provide a smooth and hopefully realistic feel. You may notice in the video a small glitch at the end of the 'move forward' animation, and these little disjoints are exactly what Mark is waiting for, and an editor like the one created will help test the fix on these very quickly as we can pin down the exact frame and how the code deals with it.

That said, the crouch is not complete. I need to formalize my new 'state engine database player' thing and make it a clean isolated module of functions and arrays, I need to add crouch move left and right, throw grenade, leap over obstacle, e.t.c. When the time comes to connect to the DarkAI system, it should allow the prototype to silkily move the character around the scene without me having to hack in and endlessly tweak values for all combinations.

Signing Off

Crouch proto resumes Wednesday, and once it's solid, move the relevant module and data over to the main AI prototype and try it out. The NEXT time a similar demand arrives (and there will be many), I should have a good generic system to simply add more data and not have to hack in anything other than additional 'methods and instructions' which can in time be re-used by subsequent behaviors and animation sequences required.

I was going to blog about some lovely new art from Mark but I've just looked and this blog is big enough for one late night post, so I will save these visual candy snacks until later in the week :)

Monday, 19 August 2013

Monday More Ladders

And Some Stairs!

Actually it's pretty much the same ladder, but it's a little better now.  Our little guy can pretty much walk around after the player no matter where I try to hide now. He currently cannot dive through windows, leaping off platforms, quick-slide down ladders, ab-sail, dive-attack, shimmy or any other wild ideas you might have for getting from one level to another, but the mechanism for using a state machine to get from UP to DOWN to UP are now in.


Amazing amount of time spent on seemingly very little as I had a character climbing and descending a ladder three days ago.  If I did this again, I would write an editor which choreographed a sequence which allows an object frame, rotation and position to be exactly controlled throughout a process of getting from A to B. At the moment the system uses a hard code state engine to get the job done. The benefit of an editor for the sequence is that once it's done, the main AI only had to get the object to A, hand over to the sequence player, then return at B to resume the AI.  Sure, it would also have taken three days, but right now I would have the tool to create staircase walking, riding lifts, grabbing a lamp-post, swinging around 90 degrees and diving through a window and all manner of cool sequences.

That said, at least the ladder climbing code is smooth enough now and transitions well from the two test ladders I have. I don't have any stair climbing animation so could not anything with the staircase transition state engine, even though it's ready and waiting, except to re-use the walking animation and slide the guy up to the next floor.  Hopefully Mark will read this and add a nice 'walk up stairs' animation in the style of the ladder animation sequence.

Over The Weekend

As you can guess, I was also battling with this over half the weekend too, tweaking the animation and motions and slowly realizing the process of tweak, run, get game to exact state, see if it works, go back to editor, tweak, rinse and repeat was massively time consuming.  Not least was testing the 'walk down ladder' which of course involved coaxing the enemy to the roof before bringing him back down again.  Another lesson is that if you anticipate a lot of tweaks in speed, motion, rotation, animation or transition then set-up your principals at their ideal starting positions. Ten minutes spent here saves hours later on!

The Last Four Hours

Of all the frustrations, the latest one which hit me around 10 PM was the sudden switching of the entity AI from container one (first floor) to container zero (ground floor), for seemingly no good reason. The container logic on the roof and the outdoor platform was fine, but my interior staircase seemed to have a large hole, be it in DarkAI or my code.  I eventually had to create a game loop within a game loop at the exact moment the AI would do this crime and start chopping out code to see what caused it. I eventually discovered none of my code caused it (as I had deleted it all by then), and it was quite true that DarkAI decided through automatic mode to switch the entity back to container AI (I guess because it was more interesting than container one).

Rather than waste any more time, the smart move was to send the whole shooting match to Paul to investigate this odd behavior while I resort to simpler implementations such as ducking, running, shooting. The easy stuff.

Signing Off

It's coming up to 3 AM now and although I have a need to move this prototype along quickly, I don't think I should do more coding with tonight's brain. Tuesday I will abandon containers for a day and focus on combat (now that our guy can chase the player).  It's fair to say I am now behind my own personal schedule as I had hoped to have all the basic AI states in place by now, but a bit more focus and few extra hours per day should see things right.  
Hopefully I can bring you a nice video in a few days once I've got the enemy putting up a good fight.  Right now he just follows me around like a puppy!

Friday, 16 August 2013

Friday Ladders

Short Blog Today

After a long day of making what felt like one million very minor tweaks to line up the character ladder animation with the AI system, I have decided although it was presentable at high speeds it was not quite right. 

The solution will be to have Mark tweak the animation so 'movement' and 'animation hand and foot positions' line up perfectly, or code some sort of animation database system whereby each frame can move the character model an arbitrary amount.  The second is better as it means characters will move around the world less 'smooth' and create a very subtle sense of realism which I think is what we are chasing here.

I will think on it more over the weekend, and move my current implementation from a test hack to a real engine feature I can use for all ladders across multiple enemies and allies.

Signing Off

I was planning to present a video, but I would not create the impression Mark had in mind when he created the ladder animation.  Rather than rush one out, I will implement some more care into the ladder stuff and the next video opportunity will show a really nice 'hopefully realistic' climb action.

I must say it is pretty cool to see the character swing onto the ladder and bolt up it giving chase, with the head limb relatively independent and looking around!  It also occurred to me that the same system could be used for staircases, so instead of the usual 'enemy sliding diagonally' up the ramp stairs, the character actually places one foot perfectly on each step and ascends properly.  Exciting visuals ahead, although I had hoped to be at the point of some small combat functionality with the player taking pot shots by Friday but it's probably the right move to aim for the best realism before moving on (as it's not rocket science).

Thursday, 15 August 2013

Thursday Visual Teaser

Visual Fun

Aside from the usual regular stuff like cleaning up source code and structuring everything so it slots nicely into the main engine (boring, zzzzz), I had the rather fun task of introducing the animated character model to the AI system for the first time.  I kept it pretty light and free-form and ended up with a neat concept whereby the character you see trails the AI entity object by a split second, allowing the real character to look ahead where he is 'going to be' and it struck me that this is what we do in real life.

We actually look in the direction where are 'going to go' rather than where we are going that split second, and when you see it portrayed visually you see what I mean. No way to describe it in words, or even screenshot it, so I loaded up with some community disclaimers (thanks guys), and made a video for you:


As you can see, as the AI entity advances ahead of the character you can see, it looks like the guy is anticipating the action he is about to commence which in this case is turning a corner. It got me thinking that the same system could be employed across many other actions and create this wonderful sense of character whereby the head and upper body observed seems to be thinking ahead, before the rest of his body catches up.  I think this is an interesting ingredient and perhaps something that can only be created in real-time, subject to circumstance.

I am sure this artifact won't work in every case, especially when the action is fast and the character must obey split second directions, but for someone casually walking about it looks pretty cool!

Signing Off

A pretty busy day in the mill of code today, so not much more to reveal past the antics of getting more and more character animations tied to AI activities. The challenge for Friday will be getting the character to 'realistically' climb the ladder, dismount, continue his searches on the roof, find nothing and come back down to continue his patrol.  Sounds simple enough, but getting all the separate animations to blend together and look 'natural' will be a bit of headache.

And once we have that looking good, to tame the code so that it's modular and flexible enough to handle multiple characters, be they enemies, allies or neutrals.  I find the excitement of visuals is short-lived and quite quickly I am brought low again to the reality that I have to make all this fancy stuff work in a practical way in a larger context.  Granted, not the worst job in the world ;)

Wednesday, 14 August 2013

Wednesday More AI Cleverness

The Growth of AI

Amazing to watch a brand new AI behavior grow and unfold, it really is. Like watching a baby grow up super super fast, with the bonus of being able to program out all the annoying crying :)  I think I prefer computer babies!

The AI Story So Far

The AI prototype now as a few more cool features like the ability to open and close off doors and windows in real-time, forcing the AI path finders to choose another route. Very important!

Aside from the many small features, the one that has kept me up to almost 3AM (against my decision to stop at 12 midnight) was the container path system. It turns out DarkAI has a rudimentary container connection system but it requires a few more bells and whistles before it can compete with what I have been building in DBP code.

Right now, my AI entity can start on the terrain circling a building on patrol, spot me, then chase me into a room and up some stairs, I can dive through the window but he does not have 'leap' yet so I lose him, but he can still see me through the window. The AI entity realizing he cannot reach me that way, recalculates and figures out a slightly longer route to the ledge I am now standing on. It appears a second ladder drops from the roof of the building to this ledge, and there is a ground floor ladder which reaches the roof. Off the AI entity trots, back down the stairs, and by now it's been a long while since he saw me escape, which means I could be somewhere other than the ledge, so to keep me on my toes he reverts to a Patrol mode, walks out the door and continues his route. One point in his patrol route allows him to spot me still standing on the ledge platform.

Now here comes the smart bit. The AI entity was instructed to 'remember' that the stairs inside the building to the window and the ledge did not work out too well 'a failure' in fact. He then thinks about another route that does not include the staircase that lead to failure (at the moment this is all he is programmed to remember). He then plots the alternative route, up the long ladder across the roof and down the shorter ladder to the ledge, which he does right away. On descending the second ladder, I am once again in his line of sight and he registers to fire.

All the above currently works in the AI system and with the addition of more containers, more paths, more obstacles and more enemies and allies, the complexity only increases to present a very dynamic combat area to navigate. Naturally there will be tweaks on the way, but the bulk of the 'path finding' is in place and I am happy with the behavior exhibited.

Character Animation

At present, all the above AI described is using debug models and artwork, ideal for testing behaviors and values, e.t.c.  I do feel though that leaving the character model out for too long will create problems come the 'union' of AI entities which move in a cludgy manner and the high quality character art that needs to walk, run, dodge and climb in a smooth liquid performance.

These two elements can remain separate but there are key hooks in both that need to be coded carefully. I am tempted to start this work before the week is out, probably while I am waiting for AI inspiration.  This is when the general public will see the AI prototype and in one voice go 'Oooooo'.

Signing Off

I am keeping today's blog short as it's 3AM and I was supposed to be resetting my body clock for the weekend - Grr.  Still, I quite enjoyed the AI tinkering and look forward to the next steps on Thursday.  The census is that my art skills are painful at best, so I am inviting a regular reader with a panache for art to produce for me a banner which I can slap on pre-release screenshots that read the slogan "Disclaimer: Visuals/gameplay/sounds are not representative of final product".  With this, I can start posting visuals again ;)

Tuesday, 13 August 2013

Tuesday Super Building Begins

What Floor Sir?

Today has been a pretty good day, with some cool new functionality demonstrated in the latest raw DarkAI prototype. As some of you DBP coders might know DarkAI uses containers to separate vertical slices of a scene to emulate a 3D environment.

The downside is that these containers cannot be connected together and effectively exist in isolation. My work today was to create a new sub-system to DarkAI which would build and administrate 'container bridge paths' which informed any AI entity where to go in order to cross over to a new container. Typically the scene is divided into about 20 containers, stacked vertically so that the terrain would be container zero, and the first floor of a building would be container one, and so on. For a cave system level, your terrain might be container five, with subterranean levels below.  

The current prototype offers up a new building template that has a door at the ground floor leading to some stairs to level one, and some ladders outside which go all the way to the roof on the third level.  Wish I could show you the screen shot but I am awaiting the professional 'developer art banner' as recommended by Rick.  Maybe tomorrow..

Explosion Floor Smoke

One of the small side projects for this evening will be to mock-up a smoke system that will hide the rather horrid sharp line often see when you place a vertical decal aligned to face the camera as it cuts the floor of the scene. 


It's only an idea of mine right now, but if it works, it should really improve the impression that the explosion we have for Reloaded is more 3D (without resorting to a true 3D particle explosion which would require DX11 and a LOT of graphics card grunt).

State Machine VS Real-Time Planning

I was sent a white paper on the AI system used in FEAR which was quite enlightening, and went about the problem of AI by creating a real-time reasoning system to figure out what AI entities should be doing at any time during the game.  

I see no problem implementing such a system, but it would take months to lay out and test, and that's before adding any in-game behaviors that fit our goals for Reloaded.  As it stands, I am pretty sure what I want to see from the AI at the moment, and have all the animations on standby ready to go in. Before I dive into a whole new approach, I want to complete the current plan and see if my ideas for a new and improved AI system works out.

I already have the AI entities hiding around corners, and navigating around large terrain features, and finding their way around multiple floors of a building. Paul is helping me work on new things such as diving for cover, jumping over low lying obstacles and perhaps a few more small tweaks.

Signing Off

While I wait for these new features to DarkAI, I might side track a little and tie in the current AI behaviors to the character animations so they appear smooth and connected, rather than disjointed and glitchy which can so easily be the case without careful consideration.