arcade-physics
Version:
Use Arcade Physics without Phaser.
53 lines • 1.84 kB
JavaScript
;
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const const_1 = __importDefault(require("../const"));
/**
* Rotates `currentAngle` towards `targetAngle`, taking the shortest rotation distance. The `lerp` argument is the amount to rotate by in this call.
*
* @function Phaser.Math.Angle.RotateTo
* @since 3.0.0
*
* @param {number} currentAngle - The current angle, in radians.
* @param {number} targetAngle - The target angle to rotate to, in radians.
* @param {number} [lerp=0.05] - The lerp value to add to the current angle.
*
* @return {number} The adjusted angle.
*/
const RotateTo = (currentAngle, targetAngle, lerp) => {
if (lerp === undefined) {
lerp = 0.05;
}
if (currentAngle === targetAngle) {
return currentAngle;
}
if (Math.abs(targetAngle - currentAngle) <= lerp || Math.abs(targetAngle - currentAngle) >= const_1.default.PI2 - lerp) {
currentAngle = targetAngle;
}
else {
if (Math.abs(targetAngle - currentAngle) > Math.PI) {
if (targetAngle < currentAngle) {
targetAngle += const_1.default.PI2;
}
else {
targetAngle -= const_1.default.PI2;
}
}
if (targetAngle > currentAngle) {
currentAngle += lerp;
}
else if (targetAngle < currentAngle) {
currentAngle -= lerp;
}
}
return currentAngle;
};
exports.default = RotateTo;
//# sourceMappingURL=RotateTo.js.map