petemac Posted October 4, 2015 Share Posted October 4, 2015 Hello Everytime I try to do something at the end of my animation with onAnimationEnd, it happens at the start of my animation or it doesnt work at all.I try to alert at the end of my animation in this example below and I get the alert as soon as the animtion starts playing instead.var ani = 0;var sceneready = false;var playable = false;BABYLON.SceneLoader.ImportMesh("", "firstpersongame/", "human25.babylon", scene, function (newMeshes, skeleton) { });scene.executeWhenReady(function (){sceneready = true;});function theendani(){ani = 1;}scene.registerBeforeRender(function () {if(sceneready){myMesh = scene.getMeshByName("HumanMale");myMesh.position = new BABYLON.Vector3(0, 1, 0);sceneready = false;playable = true;}if(playable){if(ani == 0){//All of these play the animation once but do not trigger the ani = 1 at the end of the animation//For some reason I am getting the alert right when the animation starts//I realize they are commented out I tried each of these individually:ani = 5; // So it doesnt call beginanimation again.//scene.beginAnimation(myMesh.skeleton, 85, 105, false, 1.0, ani = 1);//scene.beginAnimation(myMesh.skeleton, 85, 105, false, 1.0, ani = false);//scene.beginAnimation(myMesh.skeleton, 85, 105, false, 1.0, theendani());//scene.beginAnimation(myMesh.skeleton, 85, 105, false, 1.0, onAnimationEnd(){ani = 1;});//scene.beginAnimation(myMesh.skeleton, 85, 105, false, 1.0, onAnimationEnd(ani = 1));//ive also tried setting the animation to loop = true and it still triggers onanimationend at the start of my animation and then just loops the animation}if(ani == 1){//scene.stopAnimation(myMesh.skeleton);//scene.beginAnimation(myMesh.skeleton, 1, 85, false, 1.0);alert("end");ani = 2;}}}Also how do you tell what frame the animation is on? Custom time tracker?For example if I wanted onAnimationEnd to be called at frame 99 of my animation. Quote Link to comment Share on other sites More sharing options...
petemac Posted October 4, 2015 Author Share Posted October 4, 2015 I figured it out.scene.beginAnimation(myMesh.skeleton, 85, 105, false, 1.0, function (){ani = 1;});works correctly. This will allow you to see what animation frame you are on:var anim = scene.getAnimatableByTarget(myMesh.skeleton);var currentFrame = anim._animations[0].currentFrame; GameMonetize 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.