Jump to content

Character locomotion animation blending


Recommended Posts

Hi guys
I'm writing the locomotion algorithm for a character I created in blender.
What I'm trying to achieve is a blend tree that will allow me to blend between the "walk-front", "strife-left" animations according to the velocity of my character (something similar to  https://www.youtube.com/watch?v=Xx21y9eJq1U&feature=youtu.be&t=1263).
I've been able to blend between two frames, by calculating a weighted average of the transformation matrix for each bone, so far so good.
Now before going on with my development I'm asking myself the following design question.


Supposing I will have a state machine to control the character, should I write an update(dt) method called at each engine tick and reposition its bones individually or rather bake at run-time a new animation with frames each time the direction/velocity changes?

I just do not know the pros/cons sticking with Babylon Animations versus going on with my own update method.

What I like of using Babylon Animations is the fact that I can fast up / slow down my walk cycles so to simulate faster/slower velocities.

Thank you in advance for any feedback,

Link to comment
Share on other sites


You had nearly the same idea as I had! (baking weighted combination of animations).

Calculating many bone matrixes of multiple animations on multiple meshes every frame, it would be too heavy I think.


Maybe a transition between walk-front and strife-left (and back) would look better than baking steps between.


Then you would need to write only one function, which bakes two full new animation transitions.

walk-front_to_strife-left and strife-left_to_walk-front.


Edit: it maybe could be part of Babylon animations. Everyone has this same problem with animation blending. ;-)


Edit 2: I think the transition time would look best if it is two to four times of the animation cycles. Like if the front animation is 60 frame / cycle and the strafe is also 60 frames, the transition would be a multiple of this, like 120 or 240 frames. Just an idea :)

Link to comment
Share on other sites

Hi BitOfGold, thanks for your inputs.


For locomotion, my idea is to have the character move smoothly in all 365 degrees, placing footstep precisely in the direction of movement.


I will do the animations now and test the performances.

Maybe it will be acceptable to calculate each bone, since I will have just two character and I plan to limit the locomotion animations to the lower part of the body of my bipeds, and use other default animations on the top. Only tests will tell.

Worst case, according to their size in memory, I could pre-bake a limited set of them to a given approximation, e.g. one each 30 degrees.


However, the idea of pre-baking transitions is interesting, I think I will use it to blend particular animations on the upper half of the body.




Link to comment
Share on other sites

Hi all,

for the records, I created my animations, I did some refactoring to have all the code controlling the character in a dedicated class.

Then I created a basic state machine and an update(dt) function which gets invoked by the runRenderLoop callback.


According to the direction of movement the character is required to perform, my code picks two same-length animations and interpolates the currentFrame of these two animations with a weighted average.

Currently, with no caching of frames and looping through all bones (even not used ones) the performances are perfect.


The blending result when interpolating the walk-front and walk-left animations is quite realistic, I will keep the optimizations for later.


When I'll have reached a stable point I will link some screen captures.



Link to comment
Share on other sites

  • 1 year later...

Yo @Deltakosh I know this is an old post... But it looks like it is possible to play blended weighted animations ... I need to get BlendTrees working right.

Right now I am interpolating between animations and it does not look quite right... I need to be able to blend animations like a Walk Forward blended with a strafe left animation.... Simply interpolating between then is not working.

I know your a busy guy. But if you can help me with this it would be great for all babylon toolkit users to create more modern animations for out characters.

It also looks like you can play different animations of different bones... so I should be able too use the Unity Animation Mask feature to make the bones in the avatar to play different animations from different layers... Like running while swinging a sword ... I can get to all this information (which is serialized as metadata)... Blend tree info, layer mask info and tons of other unity animation information needed to fully re-create the whole Unity Animation System.

Its just in the BabylonJS layer I don't know what it means to 'Play Weighted Animations' or how to even go about this at all in Babylon...

But this guy @santarcade seems to have been able to do it. 

Again.. I know your busy... But can you please work with me a bit (actually hooking up in some kind of gotomeeting or some kind of actual conversations would be freakin awesome... There are a few things things I just cant finish by myself)

Note: Any other BabylonJS Gurus out there... IF you can help... Please... I really wanna get a good working version of the toolkit out for all to use :)


Link to comment
Share on other sites


I think blending animations is easy now like this, so no need for pre baking animation transitions anymore:

I don't know nothing about Unity Animation Mask, but I understand that swinging a sword while running thing...

To understand babylon's animation system in detail, I recommend you to look at an animated model's object structure
mesh->skeleton->_animatables  this stores the animations of each bone.
in _animatables there are animations, most (keyframed, skinned) models have one animation.
in each animation there are _keys, this stores the transformation matrix of that bone at that frame/moment.
in the animation there are also _ranges, there store only frame ranges of the animation.

Maybe this helps...



Link to comment
Share on other sites

@BitOfGold Thanks for the reply :)

But yeah, I got that part... That is actually the backbone of my "Animation Retargeting"... I sample the Skeleton in unity for EACH bone and EACH frame and create a Matrix4x4 using the translation position, rotation and scale in World Space and use that as the key frame value for the _matrix property... I also natively support "Blending Speed" for "Transitioning" animations... Also working great... But for BLEND TREE... where you might wanna "BLEND" grounded locomotion states... For example... Pushing UP/LEFT on the gamepad should move in the LEFT/FORWARD diagonal movement... In the blend tree scenario you would play a 50/50 blend of the WALK FORWARD animation with the LEFT STRAFE animation... I guess you take a weighted average of the two (or more) bone matrix value and play that mix... which in our case would have LEFT/FORWARD animation movement...

I just don't know how in babylon js to play a weighted average of multiple animation frames... The Unity masking part... allows you to MASK off parts of the skeleton and assign animations from different layers to different body parts (like upper swinging a sword and lower running ... maybe even blend tree on bottom and another blend tree for top)... I think I can serialize WHAT bones of the skeleton are masked and play different animation for bones that are in the mask... that will come later... but if you can play different animations on different bones like it says you can in the post above... its just a matter of me serializing the info out of unity that says what bones should be playing what animations... That should work... we will see when I get there... but yeah that should work.

But I gotta get "Blend Tree" working for it to look right :)


Link to comment
Share on other sites

hahaha.  I'm honored that you think I'm smart enough to have a useful comment.  Thx!  No, that kind of stuff is out of reach for me.  Sorry.  But I can talk aimlessly on a related topic...

Strafing.  ie. side-stepping.  When is a controller right-pull (east?) considered a strafe, and when is it considered a turn-player-eastward-then-begin-walking-forward?

Two possibilities for a single right-pull on the joystick.  Drastically different animation sequences needed for each!  And, different follow-camera operations needed for each.

Doesn't this make your brain hurt, Mackenoid?  Maybe I'm hallucinating again.  :)

A blend tree?  What the hell is that?  No wait, I probably don't want to know. I've added 'blend tree' to my browser parental control DB, so I don't accidentally search for it.  :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   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.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...