Rect following mouseX slowing speed problem

I have tried changing this line -xVel = xVel*0,999- here but I can’t find a way to make the ellipse more gradually lose speed. Here is my code

float ellipseXPos = 300;
float ellipseYPos = 300;

float xVel = 1;
float yVel = 1;

void setup() {
	size(600, 600);
	background(0);
	frameRate(30);
}

void draw() {
	
	background(0)
	ellipseXPos = ellipseXPos + xVel;		
	ellipse(ellipseXPos, ellipseYPos, 40, 40);
	xVel = xVel*0,999;

	if (mousePressed) {
		xVel = mouseX/10-ellipseXPos/10;
		print(xVel);
	}
	}
1 Like

like this…?


float ellipseXPos = 300;
float ellipseYPos = 300;

float xVel = 0;
float yVel = 0;

void setup() {
  size(600, 600);
  background(0);
  frameRate(30);
}

void draw() {
  background(0);
  ellipseXPos = ellipseXPos + xVel;    
  ellipse(ellipseXPos, ellipseYPos, 40, 40);

  xVel = xVel * 0.8999;

  if (mousePressed) {
    xVel = (float) mouseX/10.0-ellipseXPos/10.0;
    print(xVel);
  }
}

2 Likes

Yup thanks! I don’t know how I did not see that.