0
votes

Hi I am new to aframe trying to create buttons on the screen (like the full-screen VR mode) to mimic wasd controls.

I tried info on this Link it gave me some hint regarding this but did not solve my query.

If you guys have any idea please let me know.

and also I tried broadcasting keyboard events they did not help either.

here is the camera code i tried this but nothing happened
<a-camera id="myCamera" universal-controls="movementControls: custom, touch;"> <a-cursor id="myCursor" color="blue"></a-cursor> </a-camera>

-Thanks

1
Share some code in a minimal reproducible example - mplungjan

1 Answers

0
votes

If You want to move the camera when clicking at a button, just make a listener in a component:

AFRAME.registerComponent('click-handler',{
init:function(){
   let cam = document.querySelector('[camera]');
   this.el.addEventListener('click',function(e){
         let pos = cam.getAttribute('position');
         pos.z++;
         cam.setAttribute('position',pos);
   });
 });

which moves the camera forward on click. If You want to make it smooth like in the wasd controls, with 'friction', and some kind od speed, You need to make it in the tick(), where You define Your speed as if(speed>0)speed=acc+speed-friction, and make a acc peek once You click the button. You can increase the acc while holding the button, so the movement will be even smoother.