Jump to content

Character Animation Control

Naughty Alien


blog-0077503001331131865.jpgThis time, I have decided to introduce character animation control. There are several reasons for that. A lot of people asked me to give some example, and at same time, such library will be essential for following AI tutorials, so having said that, I have decided to introduce AI library, so it will be avoided confusion with corresponding command set in AI tutorials. I would like to also make note that all libraries I have released and Im planning to release, are a lite version of fully fledged feature set in game engine Im planning to sell, after my game is out, so all this is some sort of 'advert' what full version can do, in order to make people more interested about system.


Now, lets go back to topic. During game development, one of important roles are game character animations. From programmer standpoint, control of animations must be very simple, much as possible, with same rules applicable to both, gameplay character, as well as NPC's. Even more, it is important to have ability to have character easy 'switchable' between player control or some other system (cut scene manager, AI control, scripted event). So, how is it done in this library?? Very simple. First of all, during design, you will notice that there are always certain animation 'groups'. Animation inside those groups, should fall under same control scheme. Of course, it is entirely possible to have different control scheme for each animation group, but it is NOT advisable. So what are those 'animation groups' ?? Let me explain on provided example. Lets assume that our character has 2 main pose(im not sure is this proper word). In short, lets say that our character can move in normal way (standing up pose) and crouch pose. Each of this poses I call a 'group' smile.png. Animations within each group use (should use, but its not necessary), same command set. For example, when character walk while in stand up pose, we use KEY_UP so character animating in WALK animation. When we switch to CROUCH (let say hit button C as usual in games), then SAME command (KEY_UP) will make character animating in WALK animation BUT in crouch pose. Also, while character doesnt move at all, it should be in 'STOP' animation. That animation plays main idle and if player doesnt do anything, system should play some of side idles, if available and after it plays, go back to main idle (like, Lara Croft, bored and play various animations if player doesnt do a thing)..Library giving ability for creation of infinite number of groups and infinite number of animations within groups, so its up to designer/programmer to utilize system properly smile.png Library command set is rather simple, and yet powerful, so lets see command set.




CHARACTER = TAnimation.Create("MyCharacter.gmf",IdleTriggerTime:Int=20000)



Its animated character we want to control.



This is time representing how long will be played main idle, before plays one of randomly choosen side idles, if any. So it is time what system will wait player, before switch to one of 'boring' animations. Its exposed in milliseconds, so default value is 20000 what is 20 seconds.



CHARACTER.extract_sequence("ANIMATION GROUP NAME", "ANIMATION COMMAND NAME", firstFrame:Int, lastFrame:Int,playType:Int=CONTINOUS_LOOP, idleType:Int=MAIN_IDLE, transition:Float=0.0, speed:Float=1.0)


This command will extract animation stored in given frame range, under ANIMATION COMMAND NAME and inside ANIMATION GROUP NAME.



Thisis name of specific animation group, what will contain specific animations.



This is name of specific animation, what will be used to play specific animation, during gameplay.



First Frame of animation



Last Frame of animation



It is flag representing way animation is played. It should be left in default value (CONTINOUS_LOOP), as other modes are used for internal processing as well as for some other libraries im about to introduce later, during AI lessons. Just for info, available flags are:






But as i said, you SHOULD let it be default value only, as others are used for other things, we will see, later.



This flag tells to system what kind of animation is one to be loaded and therefore, how it will be treated. If animation is MAIN IDLE then flag is MAIN_IDLE. If animation is idle for 'bored' animation, then flag should be SIDE_IDLE. SIDE_IDLE animations are attached to MAIN_IDLE and after idleTriggerTime is elapsed, one of SIDE_IDLE animations will be played and then go back to MAIN_IDLE. If animation is not any kind of IDLE animations, then it should be flagged as NOT_IDLE. This flag will be our, walk, run, jump, die, etc, animations we control. So possible flags for animation types are:







This is value representing transition smoothnes between animations.



This value representing animation speed. Default value is 1.0.





This command will basically set choosen animation group as default one and play animation from that group with ANIMATION COMMAND NAME when program starts. Usually used to setup main idle play before game starts.


In order to play some animation in runtime, we use command



This command has to be called just once and system will play it, long as it is not called any other animation.


During runtime, we want to switch from one animation group, to another. In order to do that, we use this command:





And thats pretty much all. If you wanna free from memory all stuff, during switching levels and what not, just do this:





..and you are freeeeeee... smile.png I hope you guys will have some nice use of this library. Stay tuned as MUCH more comming..



Inside zip file is EXE. you can run it in order to see how it works. EXE contain all shaders, dll's, etc so dont put it together with shader folder of yours. Character seen in EXE example, I cant share, but source code of example is kindly provided, so you just play with your own characters. Also, library consider that all animations are stored along ONE frame line, so keep that in mind.

Installation is simple..just copy e1.mod folder in to your Bmax mod folder and you are good to go..


Library available here:



Recommended Comments

hey MG, thanks man..later ill show how this library can automatically make character play certain animations during crossing over specific obstacles..like, you running, then small wall is in front of your character and once close enough suddenly, character plays jump over wall animation and continue running as it was before wall.. :( .. many features available..

Share this comment

Link to comment

hey MG, thanks man..later ill show how this library can automatically make character play certain animations during crossing over specific obstacles..like, you running, then small wall is in front of your character and once close enough suddenly, character plays jump over wall animation and continue running as it was before wall.. :( .. many features available..

oooo sounds nice NA...

Share this comment

Link to comment

What is the source of the character you are using for your demo? I want to quickly test it, don't mind if I have to buy it somewhere.

Share this comment

Link to comment

hey MG, thanks man..later ill show how this library can automatically make character play certain animations during crossing over specific obstacles..like, you running, then small wall is in front of your character and once close enough suddenly, character plays jump over wall animation and continue running as it was before wall.. wink.png .. many features available..



Cool, sounds like something to look forward to trying m8 .. I am all in favour of things that save me having to write them .. I am also in favour of gorgeous voluptuous scantily clad women who dable in the dark arts and do magic .. but thats another story ... dont want to upset Roland ... lol

Share this comment

Link to comment
What is the source of the character you are using for your demo? I want to quickly test it, don't mind if I have to buy it somewhere.


..character is Heru, main character from my game Hidden Dawn..character u saw is actually LOD2 level, and because its going to be used in one of my games, I couldnt share it, not that im stingy :(


Next library is controller control library, what will be blended with existing one. After that, everything will be ready for AI tutorials.

Share this comment

Link to comment

Cheers, count me in as a customer for this library. After reading (and re-reading) it sounds ideal. The remaining hard part is then writing the control logic. Going from a prone to a kneeling state, then aiming, that sort of thing.

Share this comment

Link to comment

..full version will introduce very easy logic setup for all controls, switching, speed of animation casted over to controller, automatic animation play when character moves over certain obstacles (like you are running and small wall appear, then system will automatically play animation of jumping over with adjustment of controller), cut scene manager with auto sync with sound, etc..

Share this comment

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Blog Entries

    • By Josh in Josh's Dev Blog 0
      I did a little experiment with FPS Creator Pack #75 by upsampling the images with Gigapixel, which uses deep learning to upsample images and infer details that don't appear in the original pixels. The AI neural network does a pretty impressive job, generating results that are look better than a simple sharpen filter: I doubled the size of the textures to 1024x1024. Then I generated normal maps from the high-res images using AMD's TGA to DOT3 tool, and saved the normal maps with BC5 DDS compression. The diffuse textures were saved with BC7 DDS compression. The images below are using a 4x magnification to demonstrate the difference.

      As you can see, the image that is upsampled with deep learning looks normal and the resized image looks like there is butter on the lens! It's hard to believe the above images came from a 256x128 section of an image.
      The workflow was pretty tedious, as I had to convert images to TGA, then to uncompressed or BC5 DDS, and then to BC7 in Visual Studio. Each BC7 texture took maybe 5-10 minutes to compress! So while this set represents the optimum quality for 2019 game tech, and the format for assets we want to use in LE5, the workflow has a lot of room for improvement.
      You can download the full package here:
    • By Josh in Josh's Dev Blog 2
      DPI scaling and the 2D drawing and GUI system were an issue I was a bit concerned about, but I think I have it worked out. This all goes back to the multi-monitor support that I designed back in September. Part of that system allows you to retrieve the DPI scale for each display. This gives you another piece of information in addition to the raw screen resolution. The display scale gives you a percentage value the user expects to see vector graphics at, with 100% being what you would expect with a regular HD monitor. If we scale our GUI elements and font sizes by the display scale we can adjust for screens with any pixel density.
      This shot shows 1920x1080 fullscreen with DPI scaling set to 100%:

      Here we see the same resolution, with scaling set to 125%:

      And this is with scaling set to 150%:

      The effect of this is that if the player is using a 4K, 8K, or any other type of monitor, your game can display finely detailed text at the correct size the user expects to see. It also means that user interfaces can be rendered at any resolution for VR.
      Rather than trying to automatically scale GUI elements I am giving you full control over the raw pixels. That means you have to decide how your widgets will be scaled yourself, and program it into the game interface, but there is nothing hidden from the developer. Here is my code I am working with now to create a simple game menu. Also notice there is no CreatePanel(), CreateButton(), etc. anymore, there is just one widget you create and set the script for. I might add an option for C++ actors as well, but since these are operating on the main logic thread there's not really a downside to running the code in Lua.
      local window = ActiveWindow() if window == nullptr then return end local framebuffer = window:GetFramebuffer() if framebuffer == nil then return end self.gui = CreateGUI(self.guispritelayer) --Main background panel self.mainpanel = CreateWidget(self.gui,"",0,0,framebuffer.size.x,framebuffer.size.y) self.mainpanel:SetScript("Scripts/GUI/Panel.lua", true) local scale = window.display.scale.y local w = 120 local h = 24 local sep = 36 local x = framebuffer.size.x / 6 local y = framebuffer.size.y / 2 - sep * 3 self.resumebutton = CreateWidget(self.mainpanel,"RESUME GAME",x,y,w,h) self.resumebutton:SetScript("Scripts/GUI/Hyperlink.lua", true) self.resumebutton:SetFontSize(14 * window.display.scale.y) y=y+sep*2 self.label2 = CreateWidget(self.mainpanel,"OPTIONS",x,y,w,h) self.label2:SetScript("Scripts/GUI/Hyperlink.lua", true) self.label2:SetFontSize(14 * window.display.scale.y) y=y+sep*2 self.quitbutton = CreateWidget(self.mainpanel,"QUIT", x,y, w,h) self.quitbutton:SetScript("Scripts/GUI/Hyperlink.lua", true) self.quitbutton:SetFontSize(14 * window.display.scale.y) w = 400 * scale h = 550 * scale self.optionspanel = CreateWidget(self.mainpanel,"QUIT", (framebuffer.size.x- w) * 0.5, (framebuffer.size.y - h) * 0.5, w, h) self.optionspanel:SetScript("Scripts/GUI/Panel.lua", true) self.optionspanel.color = Vec4(0.2,0.2,0.2,1) self.optionspanel.border = true self.optionspanel.radius = 8 * scale self.optionspanel.hidden = true  
    • By Josh in Josh's Dev Blog 2
      Previously I talked about the technical details of hardware tessellation and what it took to make it truly useful. In this article I will talk about some of the implications of this feature and the more advanced ramifications of baking tessellation into Turbo Game Engine as a first-class feature in the 
      Although hardware tessellation has been around for a few years, we don't see it used in games that often. There are two big problems that need to be overcome.
      We need a way to prevent cracks from appearing along edges. We need to display a consistent density of triangles on the screen. Too many polygons is a big problem. I think these issues are the reason you don't really see much use of tessellation in games, even today. However, I think my research this week has created new technology that will allow us to make use of tessellation as an every-day feature in our new Vulkan renderer.
      Per-Vertex Displacement Scale
      Because tessellation displaces vertices, any discrepancy in the distance or direction of the displacement, or any difference in the way neighboring polygons are subdivided, will result in cracks appearing in the mesh.

      To prevent unwanted cracks in mesh geometry I added a per-vertex displacement scale value. I packed this value into the w component of the vertex position, which was not being used. When the displacement strength is set to zero along the edges the cracks disappear:

      Segmented Primitives
      With the ability to control displacement on a per-vertex level, I set about implementing more advanced model primitives. The basic idea is to split up faces so that the edge vertices can have their displacement scale set to zero to eliminate cracks. I started with a segmented plane. This is a patch of triangles with a user-defined size and resolution. The outer-most vertices have a displacement value of 0 and the inner vertices have a displacement of 1. When tessellation is applied to the plane the effect fades out as it reaches the edges of the primitive:

      I then used this formula to create a more advanced box primitive. Along the seam where the edges of each face meet, the displacement smoothly fades out to prevent cracks from appearing.

      The same idea was applied to make segmented cylinders and cones, with displacement disabled along the seams.

      Finally, a new QuadSphere primitive was created using the box formula, and then normalizing each vertex position. This warps the vertices into a round shape, creating a sphere without the texture warping that spherical mapping creates.

      It's amazing how tessellation and displacement can make these simple shapes look amazing. Here is the full list of available commands:
      shared_ptr<Model> CreateBox(shared_ptr<World> world, const float width = 1.0); shared_ptr<Model> CreateBox(shared_ptr<World> world, const float width, const float height, const float depth, const int xsegs = 1, const int ysegs = 1); shared_ptr<Model> CreateSphere(shared_ptr<World> world, const float radius = 0.5, const int segments = 16); shared_ptr<Model> CreateCone(shared_ptr<World> world, const float radius = 0.5, const float height = 1.0, const int segments = 16, const int heightsegs = 1, const int capsegs = 1); shared_ptr<Model> CreateCylinder(shared_ptr<World> world, const float radius = 0.5, const float height=1.0, const int sides = 16, const int heightsegs = 1, const int capsegs = 1); shared_ptr<Model> CreatePlane(shared_ptr<World> world, cnst float width=1, const float height=1, const int xsegs = 1, const int ysegs = 1); shared_ptr<Model> CreateQuadSphere(shared_ptr<World> world, const float radius = 0.5, const int segments = 8); Edge Normals
      I experimented a bit with edges and got some interesting results. If you round the corner by setting the vertex normal to point diagonally, a rounded edge appears.

      If you extend the displacement scale beyond 1.0 you can get a harder extended edge.

      This is something I will experiment with more. I think CSG brush smooth groups could be used to make some really nice level geometry.
      Screen-space Tessellation LOD
      I created an LOD calculation formula that attempts to segment polygons into a target size in screen space. This provides a more uniform distribution of tessellated polygons, regardless of the original geometry. Below are two cylinders created with different segmentation settings, with tessellation disabled:

      And now here are the same meshes with tessellation applied. Although the less-segmented cylinder has more stretched triangles, they both are made up of triangles about the same size.

      Because the calculation works with screen-space coordinates, objects will automatically adjust resolution with distance. Here are two identical cylinders at different distances.

      You can see they have roughly the same distribution of polygons, which is what we want. The same amount of detail will be used to show off displaced edges at any distance.

      We can even set a threshold for the minimum vertex displacement in screen space and use that to eliminate tessellation inside an object and only display extra triangles along the edges.

      This allows you to simply set a target polygon size in screen space without adjusting any per-mesh properties. This method could have prevented the problems Crysis 2 had with polygon density. This also solves the problem that prevented me from using tessellation for terrain. The per-mesh tessellation settings I worked on a couple days ago will be removed since it is not needed.
      Parallax Mapping Fallback
      Finally, I added a simple parallax mapping fallback that gets used when tessellation is disabled. This makes an inexpensive option for low-end machines that still conveys displacement.

      Next I am going to try processing some models that were not designed for tessellation and see if I can use tessellation to add geometric detail to low-poly models without any cracks or artifacts.
  • Create New...