Move mesh like a camera with attachControl()

Hello everyone.

I use cam.attachControl(canvas, true) to move my camera with the mouse or fingers and it’s very convenient.
When I click on a mesh from my scene, I disables the camera control and I would like a similar control to be made to rotate and move my mesh.

This is my actual code :

	new BABYLON.ExecuteCodeAction({
			trigger: BABYLON.ActionManager.OnPickTrigger,
		function (event) {
			const pickedMesh = event.meshUnderPointer
			// how move my mesh with fingers or mouse here ?

Is there a simple way to do this ?
I’m starting with Babylon.js and if my code can be simplified, I’d like to know how.
Thank you :slightly_smiling_face:

Unfortunately, I’m not aware of a way to map the camera input types to the mesh but depending on your goal you could try one of the following:

Listening to key inputs manually to update the mesh: (eg.
Listen to pointer observables to update the mesh (eg.
Using gizmos to manipulate the mesh (eg.

For camera’s I’ve often also found that I use an existing camera input type to get started quickly but once I want a bit more custom movement (eg. for a game character or object following) I end up manually controlling a freeCamera.

1 Like

Thank you so much. I will try this :yum:

1 Like