Lerp movement

Hi there,

I made a lerp() function but it does not work in the way i prefer. I want to make a lerp movement for the x and y axis from left to right and from top to bottom. So, if the ellipse hits the coordinate 'width/2' with a lerp funtion, the ellipse goes to the right. Can some one help me? Thanks

float x = 0; float y = 0;

void setup() { size(500, 400); fill(255, 0, 0); noStroke(); } void draw() { background(255); ellipse(x, y, 20, 20);

x = lerp(x, width/2, 0.1); y = lerp(y, height/2, 0.1);

if (x > width/2{ x = width/2; x = -x; } }

Tagged:

Answers

  • this looks like it will ease the movement to slow down gradually, manipulating the third argument, 0.1 will make it linear, is that what you want?

  • Please edit your post (gear icon in the top right corner of your post), select your code and hit ctrl+o to format your code. Make sure there is an empty line above and below your code.

    Please, provide more details. Tell more about what you want to do, what do you picture in doing with this code with words. remember, a story has a beginning, a body and an end :-B

    Kf

  • look at the reference for lerp, normally it's used in a for loop or with the amt parameter

    to make a ball move, instead of lerp normally we add something speedx,speedy to its position x,y like

Sign In or Register to comment.