void update(){
steps = pos.size()-1;
text (counter, 150,20);
fill(255);
text(index,200,10);
fill(col);
if(forward){
if(index==0){
if(pos.size()>0){
counter = pos.size()-1;
}
//if(lim>0){
// vx += Limit(vx,lim);
// vy += Limit(vy,lim);
//}else{
if(vx>4){
vx = 4;
}
if(vx<-4){
vx = -4;
}
if(vy>4){
vx = 4;
}
if(vy<-4){
vx = -4;
}
x += vx;
y += vy;
pos.add(new PVector(x,y));
vel.add(new PVector(vx,vy));
}
else if(index ==1){
x = pos.get(counter).x;
y = pos.get(counter).y;
counter++;
if(counter == pos.size()-1){
index = 0;
}
}}
else if(backward){
if(counter>0){
index = 1;
vx = vel.get(counter).x;
vy = vel.get(counter).y;
x -= vx;
y -= vy;
//x = pos.get(counter).x;
//y = pos.get(counter).y;
counter --;
if(counter<pos.size()-1){
pos.remove(pos.size()-1);
}
if(counter == 0){
index = 0;
}
//steps = counter;
}}
else if(pause){
}
};
This is the code I have for a physics sim i am writing, I want it to be able to go forward and backwards, it works fine providing that I go back completely but otherwise the pattern changes. Not sure what to do on this one.
full code