A-Frame-Examples icon indicating copy to clipboard operation
A-Frame-Examples copied to clipboard

How to use extended-wasd-controls with cameraRig + cameraHead ?

Open Turtleted21 opened this issue 3 years ago • 2 comments

Hello Your examples show how to use extended-wasd-controls with one camera. My project is setting with 2 cameras entity, a cameraRig to move and a cameraHead to look. ( because can work in VR too ) How I can set extended-wasd-controls to control cameraRig/move with a joystick and cameraHead/look with another joystick ?

Thanks

Turtleted21 avatar Apr 28 '21 10:04 Turtleted21

I created 2 components like this, it work : `

  // need to run javascript code after a-scene entities and components are loaded
  AFRAME.registerComponent('screen-controls', 
  {
    init: function () 
    {
        this.component1 = document.getElementById("cameraRig").components["extended-wasd-controls"];
        this.component2 = document.getElementById("cameraHead ").components["extended-wasd-controls"];
        this.joystick1 = new Joystick("stick1", 64, 8);
        this.joystick2 = new Joystick("stick2", 64, 8);
      },

      tick: function(time, deltaTime)
      {
        // console.log( joystick1.value )
        // console.log( this.component.movePercent )
        this.component1.movePercent.x   =  this.joystick1.value.x;
        this.component1.movePercent.z   = -this.joystick1.value.y;
        this.component2.rotatePercent.x = -this.joystick2.value.y;
        this.component2.rotatePercent.y = -this.joystick2.value.x;
        
        
      }
  });


</script>`

what do you think about my code? thanks

Turtleted21 avatar Apr 28 '21 11:04 Turtleted21

ah it don't work, my move is "absolute", it don't take take into account the rotate coming from the joystick2.

Turtleted21 avatar Apr 29 '21 09:04 Turtleted21