kaitek666 Posted April 5, 2017 Share Posted April 5, 2017 Hey! It's me again Since I started using BJS as my game engine, I've came across some problems I couldn't understand, but animations are the hardest for me. Using this.tutorial I created an animation on my loaded model with several meshes. When I want to run my animation (here's a default one, from tutorial) only one (first) mesh is being animated. Am I doing something wrong? RockRaider.prototype.walk = function() { var animationBox = new BABYLON.Animation("myAnimation", "scaling.x", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); var keys = []; keys.push({ frame: 0, value: 1 }); keys.push({ frame: 20, value: 0.2 }); keys.push({ frame: 100, value: 1 }); animationBox.setKeys(keys); this.raider.forEach(function (mesh) { mesh.animations.push(animationBox); }); this.raider.forEach(function (mesh) { scene.beginAnimation(mesh, 0, 100, true); }); } Please note: Putting them in separate forEach wasn't necessary. Firing them at once does not solve the problem. I tried this solution as well, but it didn't do the trick: animationBox.setKeys(keys); this.raider.forEach(function (mesh) { mesh.animations.push(animationBox); // scene.beginAnimation(mesh, 0, 100, true); }); for(i=0; i<this.raider.length; i++){ scene.beginAnimation(this.raider[i],0,100,true); } Cheers!Kajtek Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 5, 2017 Share Posted April 5, 2017 Hello this is because animations cannot be shared. You need to create an animation per mesh kaitek666 1 Quote Link to comment Share on other sites More sharing options...
kaitek666 Posted April 5, 2017 Author Share Posted April 5, 2017 Thanks @Deltakosh! I didn't know that! My code is fine now, I put everything in one forEach(). It's working! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 5, 2017 Share Posted April 5, 2017 Excellent news! kaitek666 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.