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 :

myMesh.actionManager.registerAction(
	new BABYLON.ExecuteCodeAction({
			trigger: BABYLON.ActionManager.OnPickTrigger,
		},
		function (event) {
			const pickedMesh = event.meshUnderPointer
			app.$data.opened.scene._activeCamera.inputs.clear()
			console.log(pickedMesh.getPositionExpressedInLocalSpace())
			// 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. https://playground.babylonjs.com/#15EY4F#0)
Listen to pointer observables to update the mesh (eg. https://playground.babylonjs.com/#C245A1#0)
Using gizmos to manipulate the mesh (eg. https://playground.babylonjs.com/#8MGKWK#25)

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