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

**URL:** <https://discourse.processing.org/t/lerp-not-working-as-expected-in-animation-between-array-position-values/22670>\
**Category:** Coding Questions\
**Created:** [July 16, 2020, 8:09pm UTC](https://discourse.processing.org/t/lerp-not-working-as-expected-in-animation-between-array-position-values/22670 "2020-07-16T20:09:06Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![fpalla](https://avatars.discourse-cdn.com/v4/letter/f/3da27b/32.png) [@fpalla](https://discourse.processing.org/u/fpalla)\
**Post date:** [July 16, 2020, 9:29pm UTC](https://discourse.processing.org/t/lerp-not-working-as-expected-in-animation-between-array-position-values/22670/5 "2020-07-16T21:29:27Z")

</div>

Oh, now I get it. Also understood my issue. **I wasn’t keeping the current position anywhere.**  
[This is what I was after.](https://editor.p5js.org/fvalla/sketches/QtWfF-WLR)

Thank you so much!

```auto
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](https://discourse.processing.org/u/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!

---

_[View the full topic](https://discourse.processing.org/t/lerp-not-working-as-expected-in-animation-between-array-position-values/22670)._
