Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 27 May 2013
Offline Last Active Dec 14 2014 02:06 AM

#5195150 Synchronising animations within a blend tree

Posted by on 28 November 2014 - 05:54 AM


This is actually the issue, you can't really do that. In order to smoothly blend, you need to know both speeds. You can't blend one side from 0 - 1 because that would go from a stopped animation to the full speed.

Ok i think i understand how you handle it.


In my solution it worked like this:

animation.play( normalized length of the clip from 0 - 1 )

And i knew the velocity of each motion and they were aligned so if one motion had the left-foot-hit-ground on 0.5 the other clips would also have left-foot-hit-ground on 0.5.

Now if i have a walk clip with 1m/s (if played from 0-1) and i needed 3m/s i would simply speed up the replay of this clip (*3), then if i say a run cycle fits better cause it has a original speed of 1.5m/s i would run this clip with *2 of the normal speed and crossblend the weights of both clips (the new clip with 0 at the beginning, _not_ the speed but the weight).


You are right thought that then your animations are not aligned any more. The best solution i saw for this problem was with Rune Johansens Locomotion solution for unity. Basically each leg is analyzed on it`s own for each walk-cycle. And the main states are stored (the positions in the cycle also normalized) for each leg, foot-hit, rest-position, foot-lift.. Then if your character has to walk 45° to the left a strafe-left and walk-forward motion are mixed and aligned based on the previous analyzed data.


You probably want to look into the source code and the thesis of this:


#5195044 Synchronising animations within a blend tree

Posted by on 27 November 2014 - 02:52 PM

Wow as you can`t see the solution i don`t see the problem ;)


Since your animations are aligned and you can play them at any speed you can play any blend-node at any speed. Only thing you have to know is the speed each walkcycle has, meaning, you have to know the distance the character would actually travel with each walkcycle. So if you blend a walk-cycle with a "speed" of 1m/s and a run cycle with 2m/s you know how far the character would travel if you mix them 0.5/0.5 so you know ...


I want to add:


I think I might be getting into territory where I'm trying to cater for use cases I'll probably not need.

That might also be true. I wrote one blend-tree implementation and in the end i only needed to blend between the walk, idle and run cycles + foot alignment. The rest where overrides like for the upper body wich didn`t complicate things.

#5114307 Using one instance of Behaviour Tree for many agents?

Posted by on 04 December 2013 - 07:35 AM

On aigamedev you will also find the behaviour tree starter kit. It is fine to learn how they actually work. But basically each entity/agent has it`s own copy of a tree. Basically you want to be able to copy each node in a tree with childs. Then you can always use a subtree in different places. So you can make different trees who share same subtrees. You could then at runtime change a subtree for one agent but not for the others who use the same big root-tree.


Having one instance of a tree working with multiple entities is a bad idea IMO. A BT represents the ai state of one entity. How would you store the state of all the enitites currently using a tree inside the tree? One would be executing a seletor "find cover" while another would be "shoot with machine gun", every node would have to store the state for each entity. The next problem would be that you could not change a subtree for one agent only. Imagine a agent gets a new kind of attack, you would inset a special subtree in an attack subtree, but you can`t cause the other entities don`t have this kind of ability.


Think of the BT as the brain of an entity. You don`t want to share a brain :)

#5114112 Component entity system - create from template

Posted by on 03 December 2013 - 01:32 PM

I would probably arrange things differently.. I will try to describe it with examples.

I would use Entities, Components, Nodes and Systems. Ok what are they..


Entity: Could be just a UID

Components: Things like a 3D-mesh component, visibility-component, location in 3d-space component, AI-component ..

Nodes: below..

Systems: Render System, AI-System, Pathfinding-System


When game data is loaded there are basically a set of components describing an entity. Like a mesh-component with the filename and the like and probably an ai-component. The component is only a set of values with some sort of identifier.


Then this set of components is examined. Means all systems check if they want an entity having this _combination_ of components. If the render-system sees a entity having a mesh-component and a visibility component it creats a render-node for this entity and stores this in a list, dictionary, vector or whatever..


On each frame each systems iterates over the nodes it has and does it`s work. If an entity looses a component the systems are notified about that and check if they have to destory/remove the respetive node (Or some other piece of code does this and only notifies the systems loosing a node/entity). For example if a entity looses its visibility-component the render-system may want to remove the render-node but the resources-system may want to keep its resource-node.

In pratice most system will need to share data. So the goal should be to try to group data as much as you can if the data is not shared by multiple systems, if data is shared by multiple systems, spread it in different components. The way systems will store the entites/component-sets will be different from system to system, most systems will probably use a simple list, others will use a different way cause they want to process the nodes with multithreading or have a search tree or whatever.

To identify if an entity has a set of components a component could have an integer-id and the check if a entity has a set of components could be done with bit-masking. (The check which is done when an entity is created and the systems want to know if they "want" this entity).


just my ..