We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 5a7a0a8 + 4ec5ca7 commit b0ef543Copy full SHA for b0ef543
1 file changed
src/math/p5.Vector.js
@@ -2043,8 +2043,16 @@ class Vector {
2043
* }
2044
*/
2045
setHeading(a) {
2046
- if (this.isPInst) a = this._toRadians(a);
2047
- let m = this.mag();
+ if (this.dimensions < 2 || this._values.slice(2).some(v => v !== 0)) {
+ p5._friendlyError(
2048
+ 'p5.Vector.setHeading() only supports 2D vectors (z === 0). ' +
2049
+ 'For 3D or higher-dimensional vectors, use rotate() or another ' +
2050
+ 'appropriate method instead.',
2051
+ 'p5.Vector.setHeading'
2052
+ );
2053
+ return this;
2054
+ }
2055
+ const m = this.mag();
2056
this.x = m * Math.cos(a);
2057
this.y = m * Math.sin(a);
2058
return this;
0 commit comments