Crysis’ CryEngine 2: Flow Graph Tutorial

Some of you may be familiar with the Crysis game released by the German company, CryTek.  CryTek has been repsonsible for developing several popular game engines such as the Far Cry engine which is now owned by UbiSoft.  

CryTek’s latest and greatest engine is called CryEngine2.  CryEngine2 is comparable to the Unreal3 game engine.  CryTek has been generous enough to release their game editor for free to those who purchase Crysis Warhead / Wars game.  I have recently been working with the CryEngine2 game engine and thought I would share some of my findings regarding the scripting.

As more and more next generation game engines are starting to come out, they are beginning to use these visual based approaches to scripting.  For example, the Unreal Tournament 3 game engine uses a Visual programming language called Kismet to handle its high level gameplay logic.  There are several advantages to using a visual programming language.  Visual programming languages generally use nodes whose code is tried tested and proven to work.  Normally these nodes will be highly efficient as well and will not suffer from misuse of resources.  Finally,  visual programming languages allow developer to better organize their logic in a visual manner which allows them to implement better desigins.

The CryEngine2 utilizes several different methodologies for scripting.  It has a high level visual programming language called “Flow Graph”, which is what I will be talking about in this article.  In addition to that,  developers can write scripts in C++, Lua, and ActionScript.  When you start out developing mods for Crysis Wars,  you will probably start scripting with Flow Graph and work your way down to C++ and Lua based modules.  Flow Graph is a very convenient programming language in which a developer can link together different nodes to develop game logic.  The nice thing about FlowGraph is that it is easily expandibly.  Flow Graph ships with over 900 different nodes which are equivalent to classes in OOP based languages like C++, C#, and Java.  These nodes range from handling vector math to changing a soldier’s animation.  If you can’t manage to find a node that meets your need,  you can easily write your own nodes in C++ or Lua.

In this article,  I want to give a breif tutorial on how to use Flow Graph.  I am not going to cover how to setup a map with Soldiers or anything of that nature.  If you would like to know how to do that, you can check out the Crysis mod portal which contains ample tutorials on how to do those kind of things.

Here is a sample Flow Graph that I developed with CryEngine2.

Essentially what this graph does is control an enemy soldier.  He will patrol his area for 10 seconds, after which he will walk behind a truck and urinate.  After he is done,  he will walk back to his patrol area and repeat this action after another 10 seconds passes.

We first start out with the “Start” node.  The Start node will fire the ouput trigger as soon as the soldier is spawned.  Next I use a “Logic:Any” node to handle multiple inputs.  If you are a traditional C++ programmer,  think of a “Logic:Any” node as an OR statement.  

if(bGameStart || bSoliderIsPatrolingAgain)

Next we use the “Time:Delay” node which basically does what it says. We give it amount of time in seconds to wait, which in our case is 10 seconds, and then it will fire its Output trigger was the appropriate amount of time has passed.

The next node I added was another “Logic:Any” however this node isn’t really necessary. I added this node incase I want to scale this graph more in the future but it would be perfectly fine to directly connect the next node “AI:Goto” with the “Time:Delay” node.

The “AI:Goto” node is where we really begin to interact with our environment. The “AI:Goto” node will move a soldier from one location to another. The best part is that AI:Goto is smart enough to rotate and update the soldier’s animation for you. All you need to do is tell it is the soldier’s destination vector. We will use the “Entity:EntityPos” node to tell the “AI:Goto” node where we want our soldier to go. In the game editor, simply select another entity such as a truck and then assign that entity to the “Entity:EntityPos” node by right clicking the node and selecting “Assign selected Entity”. Pretty easy huh?

Once our soldier has reached his destination, we want to play his urination animation. Each entity has its own set of animations. Our soldier happens to have a urination animation which we will play by specifying it as a “name” parameter in the “AI:Anim” node. Once the animation is finished, the AI:Anim’s done trigger will be fired. At this point, we again use the AI:Goto node to move the soldier back to his old location. I have setup an invisible entity at his starting position so that we can know where to move back to. The invisible entity is being referenced by the second “Entity:EntityPos” node.

Finally, once the soldier reaches his original location, the AI:Goto’s done trigger is fired which is connected to our “Logic:Any” node which basically will end up repeating the ai logic all over again.

As you can see, Flow Graph allows a developer to rapidly implement game logic at a high level without worrying about so many low level details.  If you are interested in using any next generation game engine,  it is probably in your best interest to begin learning how to use visual based approaches to game development.  If you are eager to get your hands dirty with the CryEngine, you can purchase the game at Amazon.


Crysis Warhead/Wars

Crysis Warhead/Wars

I would like to give special thanks to “fuego96″ for this tutorial idea.
I hope you enjoyed this article and will find it useful!

Did you find this article useful?

View Results

Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.