Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Rotate when keydown


Benstrocity
 Share

Recommended Posts

Hello everyone. I'm knew here and also knew to Phaser 3. I'm working on a game currently where you play as a lost ball who is trying to make it back to his owner. Anyway, I have my player movement working fine. I but when I keypress "w" or "a" I want the ball to also continuously rotate (to look like it's rolling) while those buttons are held down. this.ball.setRotation() will only rotate the ball once. I've done a lot of digging and can't seem to find what I'm looking for.

 

update() {
        // Movement (left/right)
        if (this.cursors.left.isDown) {
            this.ball.setVelocityX(-225);
          } else if (this.cursors.right.isDown) {
            this.ball.setVelocityX(225);
          } else {
            this.ball.setVelocityX(0);
          }
        
        // Jumping mechanic
        if (this.cursors.jump.isDown && this.ball.body.touching.down) {
            this.ball.setVelocityY(-700);
        }
    }

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...