How to drag a cube to rotation itself

Hi, guys,
I have a question,
When I drag this cube,the cube will rotate with the mouse position

like gizmo
https://playground.babylonjs.com/#31M2AP#11

but I don’t want to show those guides line, and the gizmo must be selected under the guide line to control the model rotation and so on,
I want to point directly to the model to control its rotation in place
is there any way or other suggestion?

another demo
https://playground.babylonjs.com/#H5E3PT
thank you for watching!

Hi meleelin,

Is this something like what you’re going for?

Click to rotate mesh | Babylon.js Playground (babylonjs.com)

Essentially all I’m doing in this Playground is using Babylon’s picking system to determine when the cube has been clicked on, then rotating it as the mouse moves. The code for detecting the interaction is pretty rudimentary, so it might need more robustness work if your scenario has to run on a phone, for example, but the core idea should be the same. I chose to do my rotation relative to the camera because the cameras in the Playgrounds you originally linked were mobile, but you could also rotate relative to other directions by just changing where the upDir and rightDir vectors come from. Hope this helps, and best of luck!

2 Likes

thank u!
That’s what I want!! :laughing: :laughing: :laughing: