# Slow Movement of player to mouse position on mouse click

**URL:** <https://discourse.processing.org/t/slow-movement-of-player-to-mouse-position-on-mouse-click/26844>\
**Category:** Coding Questions\
**Created:** [January 6, 2021, 7:06pm UTC](https://discourse.processing.org/t/slow-movement-of-player-to-mouse-position-on-mouse-click/26844 "2021-01-06T19:06:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonniclass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/leonniclass/32/11695_2.png) [@Leonniclass](https://discourse.processing.org/u/Leonniclass)\
**Post date:** [January 6, 2021, 7:06pm UTC](https://discourse.processing.org/t/slow-movement-of-player-to-mouse-position-on-mouse-click/26844/1 "2021-01-06T19:06:16Z")

</div>

Hello, I am new to processing and I have to make a game were the user clicks somewhere in the window and the ball will move to the position. It is pretty simple, but I cant figure it out 😅  
I havent found something similar on the web, so hopefully this new topic is useful for everyone^^

```auto
float plposX;
float plposY;
float easing = 0.05;

void setup() {
  //fullScreen();
  size(600, 600);
  plposX = width/2;
  plposY = height/2;
  cursor(CROSS);
}

void draw() {
  background(0);
  
  //direction line
  strokeWeight(5);
  stroke(255, 255, 255, 100);
  line(plposX, plposY, mouseX, mouseY);

  //player movement
  fill(255);
  noStroke();
  circle(plposX, plposY, 40);
  if (plposX<mouseX && plposY<mouseY) {
    plposX+= (mouseX-plposX)*easing;
    plposY+= (mouseY-plposY)*easing;
  } else {
    plposX-= (plposX-mouseX)*easing;
    plposY-= (plposY-mouseY)*easing;
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 6, 2021, 7:21pm UTC](https://discourse.processing.org/t/slow-movement-of-player-to-mouse-position-on-mouse-click/26844/2 "2021-01-06T19:21:55Z")

</div>

Hey, welcome to the forum!

Great to have you here!

Your Sketch is good!

The “if” is not really necessary.

Also, in my version you can click the mouse to start the player.

Warm regards,

Chrisir

**here is my version :**

```auto
float plposX;
float plposY;

float mouseXDesired, mouseYDesired; 

float easing = 0.05;

void setup() {
  //fullScreen();
  size(600, 600);
  plposX = width/2;
  plposY = height/2;
  mouseXDesired=plposX;
  mouseYDesired=plposY; 

  cursor(CROSS);
}

void draw() {
  background(0);

  //direction line
  strokeWeight(5);
  stroke(255, 255, 255, 100);
  line(plposX, plposY, mouseXDesired, mouseYDesired);

  //player display
  fill(255);
  noStroke();
  ellipse(plposX, plposY, 40, 40);

  //player movement
  plposX+= (mouseXDesired-plposX)*easing;
  plposY+= (mouseYDesired-plposY)*easing;
}

void mousePressed() {
  mouseXDesired=mouseX;
  mouseYDesired=mouseY;
}

```

---

<div class="post-metadata">

**Author:** ![Leonniclass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/leonniclass/32/11695_2.png) [@Leonniclass](https://discourse.processing.org/u/Leonniclass)\
**Post date:** [January 6, 2021, 9:22pm UTC](https://discourse.processing.org/t/slow-movement-of-player-to-mouse-position-on-mouse-click/26844/3 "2021-01-06T21:22:54Z")

</div>

> [@Chrisir](#):
>
> ```auto
> float plposX;
> float plposY;
> 
> float mouseXDesired, mouseYDesired; 
> 
> float easing = 0.05;
> 
> void setup() {
> //fullScreen();
> size(600, 600);
> plposX = width/2;
> plposY = height/2;
> mouseXDesired=plposX;
> mouseYDesired=plposY; 
> 
> cursor(CROSS);
> }
> 
> void draw() {
> background(0);
> 
> //direction line
> strokeWeight(5);
> stroke(255, 255, 255, 100);
> line(plposX, plposY, mouseXDesired, mouseYDesired);
> 
> //player display
> fill(255);
> noStroke();
> ellipse(plposX, plposY, 40, 40);
> 
> //player movement
> plposX+= (mouseXDesired-plposX)*easing;
> plposY+= (mouseYDesired-plposY)*easing;
> }
> 
> void mousePressed() {
> mouseXDesired=mouseX;
> mouseYDesired=mouseY;
> }
> 
> ```

My god huge thanks, I can finally continue on the project!^^
