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: