spiritabsolute 1 Report post 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 Quote Share this post Link to post Share on other sites
spiritabsolute 1 Report post 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 Quote Share this post Link to post Share on other sites
spiritabsolute 1 Report post 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(); } }, Quote Share this post Link to post Share on other sites