Sketch crashing as soon as it starts playing

Hi,

I am trying to make a sketch with falling squares and circles that collide with each other as well as the right and left wall and ground, but am having trouble with the sketch crashing as soon as pressing play, without even the background being drawn or giving any error messages.

https://editor.p5js.org/bdooley7/sketches/vKKaXEzy5

I would appreciate any help as to why this may be happening.

Thank you so much in advance!

Maybe you shouldn’t declare anything named Object:

2 Likes

Thank you so much ! This got the background to draw and error messages to show up!

Now I receive a “TypeError: object1.collideWithBoundaries is not a function at /sketch.js:51:13”, and if I comment out this line, there are a bunch of other errors. Is there something fundamentally wrong with the code?

Thanks again!

All your subclasses define a method named collideWith(), but none collideWithBoundaries().

2 Likes

Hi, thank you! I have one last question : now I receive the error “TypeError: v.copy is not a function”.

I’m using the variable v in the “applyImpulse”, however when I comment these out, the same error “v.copy is not a function” is given. Does this have to do with how I’m using p5.Vector.div and object1.applyForce(GRAVITY); ?

This is how your Shape::applyForce(force) method is implemented:

applyForce(force) {
  let f = p5.Vector.div(force, this.mass);
  this.acc.add(f);
}

Static method p5.Vector.div() requires its 1st parameter to be of type p5.Vector.

But the argument GRAVITY passed to parameter force is a number: const GRAVITY = 0.5;