phaser/v3/merge/vec2/Project.js

15 lines
245 B
JavaScript
Raw Normal View History

2017-02-04 04:41:17 +00:00
// Project vector b onto vector a and return a
export default function (a, b) {
const dot = a[0] * b[0] + a[1] * b[1];
const lenV = b[0] * b[0] + b[1] * b[1];
const s = dot / lenV;
a[0] *= s;
a[1] *= s;
return a;
}