Created
April 13, 2021 21:40
-
-
Save hackergrrl/def505154b671d35e2a477d316662988 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {Number} px - Player X | |
* @param {Number} py - Player Y | |
* @param {Number} pvx - Player Velocity-X | |
* @param {Number} pvy - Player Velocity-Y | |
* @param {Number} tx - Turret X | |
* @param {Number} ty - Turret Y | |
* @param {Number} ts - Turret Projectile Speed | |
**/ | |
function getProjVel (px, py, pvx, pvy, tx, ty, ts) { | |
const x = (px + pvx * (tx - px) - tx) / ((tx - px) * ts) | |
const y = (py + pvy * (ty - py) - ty) / ((ty - py) * ts) | |
return [x, y] | |
} | |
// Example use | |
const targetVelocity = getProjVel(0, 0, 0, 0, 5, 5, 1) | |
const targetAngle = Math.atan2(targetVelocity[1], targetVelocity[0]) * (180 / Math.PI) | |
console.log(targetVelocity, targetAngle) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment