Sprite following pointer position

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.


Hello! You can use sprite picking Picking Sprites | Babylon.js Documentation (babylonjs.com)

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! :slight_smile:

You can build the dragging movement through the picking :slight_smile: 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 :slight_smile:

1 Like

Is there any example for that?

Heya, here’s the mesh dragging example 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. :slight_smile: