Using the Array of Objects Resource with unique objects

All the objects have the same x and y values each frame so they are all drawn in exactly the same place…

At this line this.y = sin(i - 90) * 120;, all the y values assigned are exactly the same for the same point on any of the carrots and at this line this.x = cos(i - 90) * 80 * noise((frameCount * 100 + i) * 0.008), the frameCount doesn’t change between the drawing of each carrot so they get the same x values too.

You can fix this by having a unique noise seed/offset for each of the Jitters in the bugs array.
e.g. this.noiseOffset = random(10000); and this.x = cos(i - 90) * 80 * noise((frameCount * 100 + i) * 0.008, this.noiseOffset).

Also you are missing quite a few semi-colons!
And make sure you’re code is properly indented (press shift + tab in the p5 web editor).

The carrots look pretty cool BTW!

Edit: Oh yeah (as @GoToLoop said), I forgot to mention you need to change translate(width/2, height/2) to translate(this.x, this.y) and use some other variables in the lines I first mentioned as otherwise you are overwriting the position of the carrot (see GoToLoop’s reply for a better answer to this part).

1 Like