I want to press the button and let the object keep running

I use 101 document’s dummy3.babylon,

            var manager = new BABYLON.GUI.GUI3DManager(scene);
            var panel = new BABYLON.GUI.PlanePanel();
            panel.margin = 0.2;
            manager.addControl(panel);
            panel.linkToTransformNode(anchor);
            panel.position = new BABYLON.Vector3(5.5,3,0);
            var button1 = new BABYLON.GUI.HolographicButton("orientation");
            button1.text = "stand";
            button1.onPointerUpObservable.add(function(){
                // alert("fuck");
                flag = 1;
                scene.beginAnimation(skelton,0,90,true,1.0);
            });
            panel.addControl(button1);
            var button2 = new BABYLON.GUI.HolographicButton("orientation");
            button2.text = "walk";
            button2.onPointerUpObservable.add(function(){
                // alert("fuck");
                if(flag==1){
                    scene.beginAnimation(skelton,91,126,true,1.0);
                }                
                flag = 0;
                while(flag==0){
                    mesh.position.z = mesh.position.z+0.5;
                }
            });
            panel.addControl(button2);
            panel.blockLayout = false;

when I click the button1,the object move unnatural,when I add the ‘while’ code,my project is stuck,how should i change my code?I only find the button’s onClickListener,I want to change it to OnPressListenr but I can’t find it

Hey!

here is a demo of how you can do it (by using BABYLON.Animation.CreateAndStartAnimation):
https://www.babylonjs-playground.com/#Q1Q3Y3

thank you,
BABYLON.Animation.CreateAndStartAnimation(“walk”, panel, “position.z”, 30, 30, panel.position.z, panel.position.z + 2, 0);
I want my button to move with object,but this code is unuseful,
panel.position.z = panel.position.z + 2;
this code have’t animation,can you give me more advice?

I think make the panel always in the camera corner is a good choice,my camera setTarget to object,when the object move,then camera move,my panel just like following camera.

1 Like

Sounds good