# Move objekt with mouse

**URL:** <https://discourse.processing.org/t/move-objekt-with-mouse/26185>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [December 13, 2020, 9:53am UTC](https://discourse.processing.org/t/move-objekt-with-mouse/26185 "2020-12-13T09:53:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wengi](https://avatars.discourse-cdn.com/v4/letter/w/c2a13f/32.png) [@Wengi](https://discourse.processing.org/u/Wengi)\
**Post date:** [December 13, 2020, 9:53am UTC](https://discourse.processing.org/t/move-objekt-with-mouse/26185/1 "2020-12-13T09:53:31Z")

</div>

Good Morning

Does anyone of you know how to move an object with the mouse. So if I go to the left with the mouse, the object also goes to the left.

With kind regards

---

<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:** [December 13, 2020, 2:59pm UTC](https://discourse.processing.org/t/move-objekt-with-mouse/26185/2 "2020-12-13T14:59:54Z")

</div>

Hello!

It’s always better when you post your code (so far you got) and explain more what you want to achieve.

But here is an example based on your (very brief) explanation.

Warm regards,

Chrisir

```auto
PVector player;

void setup() {
  size(900, 900);
  player = new PVector(width/2, height/2);
}

void draw() {
  background(0); 
  ellipse(player.x, player.y, 9, 9);
}

void mouseMoved() {

  // check x 
  if (mouseX<pmouseX)
    player.x--;

  else if (mouseX>pmouseX)
    player.x++;

  // -------
  // check y 
  if (mouseY<pmouseY)
    player.y--;

  else if (mouseY>pmouseY)
    player.y++;
} 

```
