Lerp() not working as expected in animation between array position values

Oh, now I get it. Also understood my issue. I wasn’t keeping the current position anywhere.
This is what I was after.

Thank you so much!

var x, y, easing, prevX, nextX;
var xPos = [1];

function setup() {
  createCanvas(400, 400);
  
  easing = 0.05;
  y = 50;
  x = 50;
}

function draw() {
  background(220);
  
  nextX = xPos[xPos.length - 1];
  
// Previously was prevX instead of x as the first argument, so basically kept resetting
  x = lerp(x, nextX, easing);
  circle(x, y, 50, 50);
  
}

function mousePressed() {
  xPos.push(xPos[xPos.length - 1] + 50);
  console.log(xPos);
}

@ jb4x Can I ask you if my question was clear? And if not, what could have been done better? I’m trying to get better at forums.

Thanks again anyway!

1 Like