I have never used p5 as instance in a web app before and p5.vector functions are not working. All other p5 functions are working, but when I use a datatype from p5 like p5.Vector, the setMag or setLimit functions are not working. But p5.Vector.add seems to be working.
attract(body : HeavenlyBody){
let f : p5.Vector;
let r : p5.Vector;
f = p5.Vector.add(this.pos, body.pos);
r = f.mag();
let force: p5.Vector = r;
force.setMag((this.G * body.mass) / Math.pow(r, 2));
force.setLimit(this.maxForce);
this.acc.setMag(force);
}
Oh, my badâŚI must have changed the names while trying to debug. But even with f.mag() itâs still not working.
let f : p5.Vector;
let r : number;
f = p5.Vector.sub(this.pos, body.pos);
r = f.mag();
let force: p5.Vector = f.copy();
force.setMag((this.G * body.mass) / Math.pow(r, 2));
force.setLimit(this.maxForce);
âthe setLimit and setMag functions are not working. But p5.Vector.add seems to be working.â
âŚ
error: ERROR TypeError: âforce.setLimit is not a functionâ
Yeah, they are p5.Vector types defined in the class.
pos : p5.Vector;
vel : p5.Vector;
acc : p5.Vector;
Problem isnât with those lines, definitions or initialization I think itâs because Typescript didnât recognize the vector object have setLimit function or something like that.
Iâve got an online sketch written in TS in instance mode w/ no typing errors so far!
However, it doesnât use p5.Vector. But I think itâs still worth a look:
I am having the same issue. How do you call âp5.Vectorâ while in instance mode?
This is what I get when attempting:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading âsubâ)