Skip to content

Instantly share code, notes, and snippets.

@linroex
Created November 13, 2016 18:01
Show Gist options
  • Select an option

  • Save linroex/2abf9dac98669dcbc1c4d33282cb4ac5 to your computer and use it in GitHub Desktop.

Select an option

Save linroex/2abf9dac98669dcbc1c4d33282cb4ac5 to your computer and use it in GitHub Desktop.
velocityFromAngle: function (angle, speed, point) {
if (speed === undefined) { speed = 60; }
point = point || new Phaser.Point();
return point.setTo((Math.cos(this.game.math.degToRad(angle)) * speed), (Math.sin(this.game.math.degToRad(angle)) * speed));
}
Phaser.Math.degToRad = function degToRad (degrees) {
return degrees * degreeToRadiansFactor;
};
angleToPointer: function (displayObject, pointer, world) {
if (pointer === undefined) { pointer = this.game.input.activePointer; }
if (world === undefined) { world = false; }
if (world)
{
return Math.atan2(pointer.worldY - displayObject.world.y, pointer.worldX - displayObject.world.x);
}
else
{
return Math.atan2(pointer.worldY - displayObject.y, pointer.worldX - displayObject.x);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment