Skip to content

Commit

Permalink
Add player controls with mouse (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
PuKoren authored Mar 22, 2024
1 parent 88bfb06 commit 4924e80
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/client/user-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ userManager = {
this.inputVector.set(0, 0);
if (isModalOpen()) return false;

const { keys, nippleMoving, nippleData } = this.scene;
const { keys, nippleMoving, nippleData, input } = this.scene;

if (nippleMoving) this.inputVector.set(nippleData.vector.x, -nippleData.vector.y);
else {
Expand All @@ -239,6 +239,18 @@ userManager = {
else if (keys.down.isDown || keys.s.isDown) this.inputVector.y = 1;
}

// when the mouse left click is down, we want to apply steering to the current direction of the character
if (input.activePointer.isDown) {
// we compute the current direction vector between the mouse and our character on the screen
const directionVector = (new Phaser.Math.Vector2(input.activePointer.x, input.activePointer.y))
.subtract(new Phaser.Math.Vector2(this.controlledCharacter.x, this.controlledCharacter.y))
.normalize();

// we steer the character in the direction of the mouse, so it can be used along with other controls (keyboard etc.)
this.inputVector.x += directionVector.x;
this.inputVector.y += directionVector.y;
}

const moving = this.inputVector.x !== 0 || this.inputVector.y !== 0;
if (moving) {
Session.set('menu', false);
Expand Down

0 comments on commit 4924e80

Please sign in to comment.