# Player should move on drag, shouldn’t respond on click

**URL:** <https://discourse.processing.org/t/player-should-move-on-drag-shouldn-t-respond-on-click/21194>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [May 23, 2020, 4:19am UTC](https://discourse.processing.org/t/player-should-move-on-drag-shouldn-t-respond-on-click/21194 "2020-05-23T04:19:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nis](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Nis](https://discourse.processing.org/u/Nis)\
**Post date:** [May 23, 2020, 4:19am UTC](https://discourse.processing.org/t/player-should-move-on-drag-shouldn-t-respond-on-click/21194/1 "2020-05-23T04:19:17Z")

</div>

[https://editor.p5js.org/Nis\_Collect/sketches/U0p3GjOK1](https://editor.p5js.org/Nis_Collect/sketches/U0p3GjOK1)

Above is the link of my code in p5.js editor.  
As you can see in the code that the player which is in blue colour on the preview screen, moves on mouseX and mouseY.  
I just need that player to move on dragging, it shouldn’t respond if I click over an empty region.  
Can someone please help me…  
Please…Please…Please…

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [May 23, 2020, 8:47am UTC](https://discourse.processing.org/t/player-should-move-on-drag-shouldn-t-respond-on-click/21194/2 "2020-05-23T08:47:37Z")

</div>

Hi,

Please follow the guidelines on how to post on this forum : [https://discourse.processing.org/faq#keep-tidy](https://discourse.processing.org/faq#keep-tidy) 🙂

If you want to drag your player, you need three steps :

- Detect if the mouse is pressed and inside the player image (you can use basic `if` statements)

- Use the function [`mouseDragged()`](https://p5js.org/reference/#/p5/mouseDragged) to detect when the user is dragging the mouse

- Update the player’s position, you might want to use [pmouseX](https://p5js.org/reference/#/p5/pmouseX) and [pmouseY](https://p5js.org/reference/#/p5/pmouseY) to get the difference between two mouse positions

---

<div class="post-metadata">

**Author:** ![Nis](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Nis](https://discourse.processing.org/u/Nis)\
**Post date:** [May 23, 2020, 10:14am UTC](https://discourse.processing.org/t/player-should-move-on-drag-shouldn-t-respond-on-click/21194/3 "2020-05-23T10:14:59Z")

</div>

I need to disable the movement of the player if I click anywhere over the screen.

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [May 23, 2020, 10:19am UTC](https://discourse.processing.org/t/player-should-move-on-drag-shouldn-t-respond-on-click/21194/4 "2020-05-23T10:19:23Z")

</div>

I don’t understand.

If you implement what I’ve said before, if you drag your mouse on your player then you are going to move it. Otherwise, if it’s anywhere on the screen you do nothing.

---

<div class="post-metadata">

**Author:** ![Nis](https://avatars.discourse-cdn.com/v4/letter/n/3ab097/32.png) [@Nis](https://discourse.processing.org/u/Nis)\
**Post date:** [May 23, 2020, 10:41am UTC](https://discourse.processing.org/t/player-should-move-on-drag-shouldn-t-respond-on-click/21194/5 "2020-05-23T10:41:26Z")

</div>

It isn’t working in my code…you can also try

---

<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:** [May 23, 2020, 12:20pm UTC](https://discourse.processing.org/t/player-should-move-on-drag-shouldn-t-respond-on-click/21194/6 "2020-05-23T12:20:42Z")

</div>

> [@josephh](#):
>
> Detect if the mouse is pressed and inside the player image (you can use basic `if` statements)

You can check the distance from the mouse to the player using if with dist() command - see reference
