# Sprite following pointer position

**URL:** <https://forum.babylonjs.com/t/sprite-following-pointer-position/34117>\
**Category:** Questions\
**Created:** [September 21, 2022, 8:24pm UTC](https://forum.babylonjs.com/t/sprite-following-pointer-position/34117 "2022-09-21T20:24:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rangerz132](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@Rangerz132](https://forum.babylonjs.com/u/Rangerz132)\
**Post date:** [September 21, 2022, 8:24pm UTC](https://forum.babylonjs.com/t/sprite-following-pointer-position/34117/1 "2022-09-21T20:24:14Z")

</div>

Hi! Is there a way to make a **Sprite** follow the mouse/pointer position on drag? I’m already able to do it for a mesh and for an Image in my GUI but not for a sprite.

Thanks

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [September 22, 2022, 11:44am UTC](https://forum.babylonjs.com/t/sprite-following-pointer-position/34117/2 "2022-09-22T11:44:07Z")

</div>

Hello! You can use sprite picking [Picking Sprites | Babylon.js Documentation (babylonjs.com)](https://doc.babylonjs.com/features/featuresDeepDive/sprites/picking_sprites)

---

<div class="post-metadata">

**Author:** ![Rangerz132](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@Rangerz132](https://forum.babylonjs.com/u/Rangerz132)\
**Post date:** [September 22, 2022, 12:33pm UTC](https://forum.babylonjs.com/t/sprite-following-pointer-position/34117/3 "2022-09-22T12:33:48Z")

</div>

Thanks for you quick answer. However, you can only click on the sprite via the Picking Sprites (unless I misunderstand something). I want it to drag it (sprite following the mouse). Thanks! 🙂

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [September 22, 2022, 2:36pm UTC](https://forum.babylonjs.com/t/sprite-following-pointer-position/34117/4 "2022-09-22T14:36:42Z")

</div>

You can build the dragging movement through the picking 🙂 Use picking to detect when the sprite was clicked and save the mouse position of the click, then listen for mousemove events on the stage, and move the sprite based on how much the mouse has moved from that position where the pick happened 🙂

---

<div class="post-metadata">

**Author:** ![Rangerz132](https://avatars.discourse-cdn.com/v4/letter/r/cc9497/32.png) [@Rangerz132](https://forum.babylonjs.com/u/Rangerz132)\
**Post date:** [September 22, 2022, 2:58pm UTC](https://forum.babylonjs.com/t/sprite-following-pointer-position/34117/5 "2022-09-22T14:58:16Z")

</div>

Is there any example for that?

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [September 22, 2022, 8:38pm UTC](https://forum.babylonjs.com/t/sprite-following-pointer-position/34117/6 "2022-09-22T20:38:30Z")

</div>

Heya, here’s the mesh dragging [example](https://playground.babylonjs.com/#7CBW04) that shows how to implement this technique, which you could adapt to drag sprites. Note: you can disable/hide the ground or plane that’s used to get the pointer position in 3D space. 🙂
