Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/math/p5.Vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -2189,7 +2189,19 @@ class Vector {
*/
setHeading(a) {
if (this.isPInst) a = this._toRadians(a);
let m = this.mag();
if (this.y === undefined || (this.z !== undefined && this.z !== 0)) {
const p5inst = this.isPInst ? this._pInst : (typeof p5 !== 'undefined' ? p5 : null);
if (p5inst && p5inst._friendlyError) {
p5inst._friendlyError(
'p5.Vector.setHeading() only supports 2D vectors (z === 0). ' +
'For 3D or higher-dimensional vectors, use rotate() or another ' +
'appropriate method instead.',
'p5.Vector.setHeading'
);
}
return this;
}
const m = this.mag();
this.x = m * Math.cos(a);
this.y = m * Math.sin(a);
return this;
Expand Down
Loading