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  if character needs to move some more
8. If no more movement required, return to step  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.
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 :)