Search code examples
lance

How do I move objects side to side with lance


Can someone help me make the paddles in the ponggame demo move sideways? I've added the keybinds:

  this.controls = new KeyboardControls(this);
  this.controls.bindKey('up', 'up', { repeat: true } );
  this.controls.bindKey('down', 'down', { repeat: true } );
  this.controls.bindKey('left', 'left', { repeat: true } );
  this.controls.bindKey('right', 'right', { repeat: true } );

I've also changed the game engine: processInput(inputData, playerId) {

   super.processInput(inputData, playerId);

   // get the player paddle tied to the player socket
   let playerPaddle = this.world.queryObject({ playerId });
   if (playerPaddle) {
       if (inputData.input === 'up') {
           playerPaddle.position.y -= 5;
       } else if (inputData.input === 'down') {
           console.log('you are moving down');
           playerPaddle.position.y += 5;
       } else if (inputData.input === 'left') {
           console.log('you are moving left?');
           playerPaddle.position.x -= 5;
       } else if (inputData.input === 'right') {
           console.log('you are moving left?');
           playerPaddle.isMovingDown = true;
       }
   }

}

It wont work, any help would be greatly appreciated.


Solution

  • Sorry, someone solved it for me on slack. I had to compile it with "npm run-script build". It worked after that.