Hi there.
I'm trying to create a class that wanders around the screen in a pseudo natural path. I'm taken daniel shiffman's
walker class, and used perlin noise instead of random() to create a more natural effect. It all works as expected, but if I create 2 instances of the class they both move together.
Does noise() always produce the same numbers, or is there a way for it to create different numbers for each instance
Here's a simplification of the code:
Using random() Works as expected, each instance moves on it's own random path
Code:
void walk() {
int vx = int(random(3))-1;
int vy = int(random(3))-1;
x += vx;
y += vy;
}
Using noise() All instances move together
Code:
int jumpSize = 22;
float xoff = 0.0;
float xincrement = 0.1;
float yoff = 0.0;
float yincrement = 0.11;
void walk() {
float vx = (noise(xoff)*jumpSize) - jumpSize/2;
float vy = (noise(yoff)*jumpSize) - jumpSize/2;
x += vx;
y += vy;
xoff += xincrement;
yoff += yincrement;
}
I've looked through the documentation and the Processing book (I just got for christmas :) but can't find anything that would explain this behaviour. I suspect I need to define, or initiate noise, to ensure it's instance level, rather than class level.
Any pointers in the right direction?
Thanks