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


  1. Damn dude.. I had no idea coding a simple crouch would be so involved. It's very inspiring to get deep insights like these, not all developers provide that and I have followed a few game development projects.

    Just out of curiosity, will this crouch behaviour you are programming now also be applied to the Player? I'm just wondering if the player-character's crouch-movement will be seemless like in most games or if you will "feel" the steps he takes as the video in the post implies. Also, will the Player have an actual in-game character or will it just be a camera with hit-boxes like it was in FPSC?

    I see you only mentioned forward, backwards and left/right movement. What about the movements in-between (forward left/right strafe and backwards left/right strafe)? Just some food for thought.

    Anyway, looking forward to see more progress.

  2. Hi Lee,

    I all days read your blog, what an amazing work. As a long term FPSC user, i am waiting and expecting too much from FPSC Reloaded, and i know it will be very cool! But i just would like to know about that feature of easy importing levels designed outside (3dsmax, in example). You did not forget that ya? Because i prefer design my levels entirely in 3dsmax instead of being jailed on the segments size fit, i like to model the level in 3dsmax slice it and export the level parts as entity (static entities). But i always have a lot of colision problems in actual FPSC. I hope this will be solved in Reloaded...

    Best Regards,


    1. Hello Nidal,
      how could be possible to make levels in FPSC using (example) 3dsmax? how you then place doors, buttons, enemies, items, lights etc.. on it?
      please may you address me to some infos, i'm interested in that way to make levels.
      thank you


  3. This comment has been removed by the author.

  4. Hello Lee,
    i really like that animations, it looks really natural, i joined the followers of FPSC:R last days of july (when i was informed of FPSC:Reloaded) only one month has passed but i saw a lot of progress here!! Great work!

    Best Regards - Juri

    1. Hello Juri,

      Man, this is really a great challenge for me. I really don`t like the way levels are built in FPSC (segments), because is too much work. I tried a lot of methods. The last method i tried was make the entire light inside 3dsmax using VRAY to render photo realistic scenes. It works, but is not worth trying, because you would have too much work on render to texture (bake) each level object inside 3dsmax (walls, doors, small buildings, pillars, and such), and also the texture sizes was very big (1 MB for a single 512x512) because it contains all the light information from Vray. So the best method and that works (not perfect at all, but works is this method): http://www.pdfdownloadss.com/Sketchup-to-FPSCreator-Tutorial-By-Daarboven-I-assume-you---PDF46-8808881/. But for this method work well if you want to have custom floors over which the enemies can walk normally, follow this tutorial: http://forum.thegamecreators.com/?m=forum_view&t=197834&b=21. And about lighting, is better you light your level in 3dsmax just to have a preview and to know where to place the lights in FPSC (you need to replicate the 3dsmax lighting in FPSC manually, trial and error)

    2. Understood! thank you again Nidal!

  5. Ohai Lee, me again. About that F.E.A.R. A.I. paper, could you consider
    extending that concept into a full F.E.A.R. based A.I. middleware to be developed sometime after Reloaded's release to be implemented in a variety of engines, including FPSCR? Also, could you consider potentially speaking with the A.I. Programmer of F.E.A.R., Jeff Orkin, once you have the time for it? & finally, could you consider making it a Kickstarter project much like Reloaded & the AGK you also had a hand in? Anyways, please reply & thank you for your time.

  6. Reloaded is a first person product so there is no player to actually crouch (or anything). You won't even see the hands climb the ladder, but what you will see is all the motions you would expect from jumping, landing, climbing, ducking, firing, throwing, e.t.c. Third Person is another project and another time :)

    Importing models is on the cards, and of course the new physics will ensure the object polygons are respected for collision. There will be problems importing entire 3D levels as there is lots of clever still that happens in the engine such as LOD, AI, Occlusion and many more components that rely on the assets broken up and placed individually into the level. Hopefully with the introduction of terrain and physics, importing 'buildings/features' and placing them down will be sufficient for your creative ideas.

    A future module based on the FEAR concept of AI would be a good idea, and something to look at down the road. Not sure if Jeff wants to talk with the likes of me though ;) We'll just have to bash some rocks together until we create AI fire!