Move camera by touch instead of rotation

Hi, I want to move position by touch, like scrolling in scene, I have a wide scene and y position of camera is always static, but I want to change camera x and camera z by touch, to explore scene, how I can do that?
thank you

Hello!

The best option would be to not attachControl on your camera and then manually listen to events like pointermove.

You can get inspired by the code for the freecamera:

Which camera do you plan to use?

Hi Deltakosh. Thank you for your answer. I want to see my ground like stronghold crusaders 1. I want to use FreeCamera.

Ok so for free camera you can either create your own camera input or just capture pointermove / pointerdown events and move camera.position.x / z

below function is from Interact with a Scene - Babylon.js Documentation . it is grate, but doesn’t support touch events like multi touch for zoom in and zoom out in mobile, do you know how I can handle this events too?

scene.onPointerObservable.add((pointerInfo) => {
switch (pointerInfo.type) {
case BABYLON.PointerEventTypes.POINTERDOWN:
console.log(“POINTER DOWN”);
break;
case BABYLON.PointerEventTypes.POINTERUP:
console.log(“POINTER UP”);
break;
case BABYLON.PointerEventTypes.POINTERMOVE:
console.log(“POINTER MOVE”);
break;
case BABYLON.PointerEventTypes.POINTERWHEEL:
console.log(“POINTER WHEEL”);
break;
case BABYLON.PointerEventTypes.POINTERPICK:
console.log(“POINTER PICK”);
break;
case BABYLON.PointerEventTypes.POINTERTAP:
console.log(“POINTER TAP”);
break;
case BABYLON.PointerEventTypes.POINTERDOUBLETAP:
console.log(“POINTER DOUBLE-TAP”);
break;
}
});

arcRotateCamera have this zoom behavior, How I can use it in my FreeCamera?

Hi, I solve my problem with using Getting Started - Hammer.js , it’s awesome, hope be useful for other too.

3 Likes

I was about to suggest it :slight_smile:
Unfortunately (due to some patents) the gestures are not part of the web starndards for pointer events. So you have to rely on external libs (like the fantastic Hammer.js)

1 Like

Just noting the updated Camera Inputs link.

1 Like