spiritabsolute Posted December 22, 2016 Share Posted December 22, 2016 Hi all! How to move to the point of clicks at p2js? this.game.input.onDown.add(this.onClick, this); In the event handler I have "pointer.position". What's next? I did not find a single example. I found a similar question here, but there is no answer to it. http://stackoverflow.com/questions/36120249/precision-moving-a-body-using-phaser-and-p2-js-physics Link to comment Share on other sites More sharing options...
spiritabsolute Posted December 22, 2016 Author Share Posted December 22, 2016 this.game.add.tween(this.ship.body).to({ x: pointer.position.x, y: pointer.position.y }, 1000,Phaser.Easing.Linear.None,true); this method does not seem right and it does not work properly Link to comment Share on other sites More sharing options...
spiritabsolute Posted December 27, 2016 Author Share Posted December 27, 2016 I realized this: movePlayer: function() { this.player.directionX = this.game.input.activePointer.worldX - this.player.x; this.player.directionY = this.game.input.activePointer.worldY - this.player.y; this.player.endMovePointX = this.game.input.activePointer.worldX; this.player.endMovePointY = this.game.input.activePointer.worldY; this.player.body.rotation = Math.atan2(this.player.directionY, this.player.directionX) + this.game.math.degToRad(-90); var angle = this.player.body.rotation + (Math.PI / 2); this.player.isMoves = true; this.player.body.velocity.x = this.player.walkSpeed * Math.cos(angle); this.player.body.velocity.y = this.player.walkSpeed * Math.sin(angle); }, update: function() { if(this.player.isMoves) { if(this.math.sign(this.player.directionX) === 1) { if(this.player.x > this.player.endMovePointX) this.player.body.velocity.x = 0; } else { if(this.player.x < this.player.endMovePointX) this.player.body.velocity.x = 0; } if(this.math.sign(this.player.directionY) === 1) { if(this.player.y > this.player.endMovePointY) this.player.body.velocity.y = 0; } else { if(this.player.y < this.player.endMovePointY) this.player.body.velocity.y = 0; } } else { this.stopMovePlayer(); } }, Link to comment Share on other sites More sharing options...
Recommended Posts