timetocode

Rotating bones while animations play

Recommended Posts

I'm having some issues rotating a bone while any other animations are playing. No rotation occurs until I stop/disable all of the animations that involve the same skeleton.

For example this code will rotate the torso,  but only if the animations aren't playing.

       scene.registerBeforeRender(() => {
           skeleton.bones[1].rotate(BABYLON.Axis.Y, 0.01, BABYLON.Space.LOCAL)
       })

...


       var idleAnim = scene.beginAnimation(skeleton, 0, 89, false); // set to true to stop rotation

https://www.babylonjs-playground.com/#IQN716#38

It may seem like it is because the animation has a conflicting position for the bone but I'm pretty sure that isn't why. I've made a separate model that only has animated legs, and I can't turn its head bone while the legs are moving.

It does appear to be possible though: https://www.babylonjs-playground.com/#11BH6Z#92  This pg dates back to before babylon had bone.rotate() and it does everything manually via linear alg.

Any idea what I'm doing wrong?

Share this post


Link to post
Share on other sites

So I think I've approximately isolated this behavior.

bone.rotate(...) has no effect on a mesh that is experiencing an animation, I'm not sure if this is a bug .

Example: https://www.babylonjs-playground.com/#11BH6Z#377 this guy's head should be spinning around, but it won't rotate unless the animation is stopped.

Code like this does work though:

var initMat = skeleton.bones[7].getLocalMatrix().clone();
scene.beginAnimation(skeletons[0], 0, 100, true, 1.0);
    
var angle = 0;
    
scene.registerBeforeRender(function () {
        
        var mat = skeleton.bones[7].getLocalMatrix().copyFrom(initMat);
        mat.multiplyToRef(BABYLON.Matrix.RotationX(angle), mat);
    
        angle += .01;
    
        skeleton.bones[7].markAsDirty();        
});

And here's a PG showing rotation of a torso (using the above technique) while two blended animations are playing... which amazing that it all works together!! https://www.babylonjs-playground.com/#IQN716#39 Is this intentional that this works? I ask only because depending which bone is rotated, it'll bug out and the character will sink into the ground. But rotating the first couple torso/vertebrae bones and the head bone produce the desired effect.

 

My problem is that even with this technique nothing happens to my models. If any animation is playing, then I cannot control the torso or hip bone. I've tried starting/stopping my animation and its as if my character is in two entirely different states. When the animation is playing all I can see is the animation. When the animation ends my guy's body parts are spinning. Maybe I've just done something inappropriate with the bones of my rig:

image.png.de14cf2bea795ba23d3d9539aed912f1.pngimage.png.c6c16a03351e8586541f0a6b736120d2.png

There's a nesting of bones such that root moves the whole mesh, upper moves just the torso+arms, lower moves the pelvis and legs. I thought this would be ideal for a first person shooter where the hips face the direction being traveled in while the torso faces the direction being aimed in. But maybe these nested bone relationships aren't okay? I'm going to make a new post asking for some model samples so I can learn more.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.