Walking animation in range or on ground

Hi,

I have created animation with Mixamo and its working with:

BABYLON.SceneLoader.ImportMesh("", "./3d/assets/", "female.babylon", scene, function (newMeshes, particleSystems, skeletons) {
    var skeleton = skeletons[0];

    skeleton.animationPropertiesOverride = new BABYLON.AnimationPropertiesOverride();
    skeleton.animationPropertiesOverride.enableBlending = true;
    skeleton.animationPropertiesOverride.blendingSpeed = 0.01;
    skeleton.animationPropertiesOverride.loopMode = 1;

    var walkRange = skeleton.getAnimationRange("walk");

    scene.onBeforeRenderObservable.add(()=>{
            newMeshes[0].position.z-=1
            if(!animating){
                animating = true;
                scene.beginAnimation(skeleton, walkRange.from, walkRange.to, true);
            }
    })

});

I have a walk in place animation, which to move forward, I am moving character in z direction with newMeshes[0].position.z-=1

but issue is I would like to animate character randomly inside an area, so character can automatically walk around, like it can auto walk to different XZ location within an XZ area or on a mesh, is there a way to achieve it?

Thanks

Edit:
Found something Creating A Navigation Mesh | Babylon.js Documentation

digging into it

@Cedric Thank you for super Navigation mesh plugin, I found some pretty good example of how I want to create a crowding example code here https://www.babylonjs-playground.com/#X5XCVT#199

But something I am not able to figure yet, please see this PG https://www.babylonjs-playground.com/#TMQFUB#3

in above PG, I am able to import my model , but something is wrong with animation which I don’t understand.

And I need larger space, so I increased ground and object sizes in createStaticMesh function (line 291), If I increase object sizes in createStaticMesh function, PG throws console.error that its not able to load my model. PG here https://www.babylonjs-playground.com/#TMQFUB#4

Thanks for the help.

It looks like your animation is not working with the skeleton. Maybe a scale issue?
@Drigax and @PatrickRyan are the best for exports and animation

I’m taking a look at why the navigation mesh is crashing.

1 Like

I’ve changed a few things in your PG and did a new one
Most significant change was to change the cs and ch parameters for the navmesh creation. Those values are world space and need to be adapted to your scene size.

1 Like

Thank you , I updated your PG with a fixed model to have only those 4 animations:

,"ranges":[{"name":"Idle","from":0,"to":90},{"name":"LeftStrafeWalk","from":100,"to":131},{"name":"RightStrafeWalk","from":140,"to":171},{"name":"Run","from":180,"to":201},{"name":"Walk","from":210,"to":245}]}],

so total frames are reduced to 245, and also assigned with:

    var IdleRange = rabbit.skeleton.getAnimationRange("Idle");
    var WalRange = rabbit.skeleton.getAnimationRange("Walk");
    var RunRange = rabbit.skeleton.getAnimationRange("Run");
    var LeftStrafeWalkRange = rabbit.skeleton.getAnimationRange("LeftStrafeWalk");
    var RightStrafeWalkRange = rabbit.skeleton.getAnimationRange("RightStrafeWalk");
   
    animations = [
        { start: IdleRange.from, end: IdleRange.to, offset: 0.0, speed: 30.0 },  //"Idle"
        { start: WalRange.from, end: WalRange.to, offset: 0.0, speed: 30.0 },    //"Walk"
        { start: RunRange.from, end: RunRange.to, offset: 0, speed: 30.0 },     //"Run"
        { start: LeftStrafeWalkRange.from, end: LeftStrafeWalkRange.to, offset: 0, speed: 30.0 },     //"LeftStrafeWalk"
        { start: RightStrafeWalkRange.from, end: RightStrafeWalkRange.to, offset: 0, speed: 30.0 },     //"RightStrafeWalk"
    ];

any idea why my model doesn’t walk properly and why my model’s arms are like my arms when sleeping? :sweat_smile:

PG here https://playground.babylonjs.com/#5HKFKL#7
it also includes blender file link

Thanks

@Dshah_H, have you tried using a standard Babylon material on your mesh rather than the custom material? I ask because it appears that you swap to a custom material at some point in your scene’s execution but at first you see the meshes stepping through all of the animation clips and the skeletons all look normal. I am guessing that with your custom material has a bug in the skeleton matrix somewhere that is causing the issue. Using a standard material in its place will show you if there is a problem in the custom material.

1 Like

Thanks for replying @PatrickRyan
with standardMaterial same issue remains : https://playground.babylonjs.com/#5HKFKL#9
even without any material :https://playground.babylonjs.com/#5HKFKL#8 , model stays in T pose position

edit: forgot, I am using thinInstance so only could control animation in custom material with manInstance.instancedBuffers.anim

edit: I was able to remove T pose, by removing line 75 //rabbit.skeleton.returnToRest();, but still walk animation is not correctly displaying, when its computing, model walks in reverse
https://playground.babylonjs.com/#5HKFKL#12

@Dshah_H, you had a couple of things going on there that I cleaned up.

https://playground.babylonjs.com/#5HKFKL#13

Here are the main take aways:

  • I wasn’t sure what you were trying to accomplish with your registerBeforeRender scene, so I commented that out.
  • I also commented out the calls to start the animation and placed that under a function to be called whenever you need it.
  • You only have one skeleton in your scene so when you instance your meshes from the original, you will be playing just one animation across all meshes. The skeleton is what is animating and the skin to the mesh holds the offset for each vertex from the bone. That means you can’t pass different animations to each instance as they would need their own skeleton in the hierarchy to have a unique animation. To accomplish this, you would want to clone your characters so they can keep their own state in animation. If, however, you always want all meshes to be playing the same animation, you can do that like you have here.
  • Your mesh has a default orientation that is backwards from Babylon.js, so your meshes would be walking backwards. I used your parent transform to place a 180 degree rotation for your character so they are walking in the right direction.

The reason that your meshes were all moving in T-pose is that originally you started the animation in your scene on line 60 with:

scene.beginAnimation(skeletons[0], 0, 1, false, 1.0, () => { runAnim(frameIndex); running = true; })

This was starting your scene animation on your only skeleton at 0 and playing to frame 1 and not looping. Hope this clears up what you are seeing and unblocks you to move ahead.

1 Like

@PatrickRyan thanks for taking time to look into it.

that solution may work only in case if I would like to use clones or same animation, but that isn’t the case, reason I am using registerBeforeRender and all custom material is to use instances with ability to have different animation, which I found only with above example, please see a working example of instance with different animation for each instance at Babylon.js Playground
(it takes few seconds to count all the pixels to create material for animation, once count is completed model turns to grey.)

I also updated my model with correct orientation, here is PG with updated model, https://playground.babylonjs.com/#5HKFKL#15, it is now giving different animation to each instance but model looks weird while walking , which I would like to find a fix

Thanks

@PatrickRyan for the time being I am going with your suggestion for using clones, but hopefully will find some solution to use instances for performance reasons, so I have created a new PG with few changes to your PG: https://playground.babylonjs.com/#5HKFKL#21

in above PG I have one small issue, on line 214 when agent is idle, I change animation
startAnimation(agent.mesh.skeleton, animations[0]);
and on line 226 when agent is walking I change it to
startAnimation(agent.mesh.skeleton, animations[1]);

between changing animations I get a T pose for few milliseconds, how could I skip that frame? Thanks

Edit: ah actually I fixed it by using enableBlending on cloned mesh. https://playground.babylonjs.com/#5HKFKL#22

2 Likes

@Cedric does the navigation mesh extension supports instances and thinInstance ? cause it doesn’t effect anything.

navigationPlugin.createNavMesh([staticMesh,myInstaceMesh,myThinInstanceMesh], navmeshParameters);
Thanks

Hey @Dshah_H, @Cedric is off for a few days, please bear with us while waiting for cedric

He will answer as soon as he will be back

1 Like

Hi @Dshah_H

Instances are supported. see this PG : https://playground.babylonjs.com/#HFY257#74
Thin instances are not. I’m taking a look if I can add support for them as well.

2 Likes

PR : Added support for thin instances in navigation mesh creation by CedricGuillemet · Pull Request #9432 · BabylonJS/Babylon.js · GitHub

2 Likes

Thank you so much @Cedric, … You guys are awesome, one of the best community on this planet.

3 Likes