Jump to content

Rotating bones while animations play


timetocode
 Share

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?

Link to comment
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.

 

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.

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

Loading...
 Share

  • Recently Browsing   0 members

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