I would like to imitate a scroll type behaviour in a scene with an arcrotate camera.
I want the camera to move up or down on the y axis based on inputs typically used for scrolling (such as mouse wheel up and down, two finger scroll on the trackpad, up and down arrow keys)
After disabling beta rotation of the camera, disabling ctrl to pan, and adding
camera._panningMouseButton = 1;
I get the behaviour I want by pressing middle mouse and panning.
I would like to replicate this for the other inputs mentioned above.
I canât find anything in the documentation to customise the panning input (some version of camera.keysUp or camera.keysDown but for panning?)
If there isnât a default property, I could create a custom class? I donât understand this method very well so Iâm looking for a way to solve the problem without this.
Would this functionality be easier to implement with a FreeCamera instead?
Also you can add event.preventDefault(); to your event listeners to avoid the default use of the mouse wheel.
// create a new ArcRotateCamera
var camera = new BABYLON.ArcRotateCamera(âCameraâ, 0, 0, 10, BABYLON.Vector3.Zero(), scene);
// set the desired minimum and maximum values for the cameraâs y position
camera.lowerRadiusLimit = 1;
camera.upperRadiusLimit = 100;
// listen for the appropriate input events and update the cameraâs position
canvas.addEventListener(âwheelâ, function(event) {
camera.radius += event.deltaY / 100; // adjust the radius based on the wheel delta
});
canvas.addEventListener(âkeydownâ, function(event) {
if (event.key === âArrowUpâ) {
camera.target.y += 1; // move the camera up
} else if (event.key === âArrowDownâ) {
camera.target.y -= 1; // move the camera down
}
});
canvas.addEventListener(âtouchmoveâ, function(event) {
if (event.touches.length === 2) {
var deltaY = event.touches[0].clientY - event.touches[1].clientY;
camera.radius += deltaY / 100; // adjust the radius based on the touch delta
}
});
That thing is quite smart, isnât it
In any case, I suppose starting with preventDefault() is a good start.
I would be interested to see the result of your âcollaborationâ with the AI⌠(in case you make it there).
Else, let us knowâŚ
Hi and welcome to the Community?
Good question. I would say âyesâ from the reading above but I do not have all the details. Is it like a locked angle view? Fact is the arcRotateCamera is orbital. It works from a target with alpha,beta and radius offset from the target. Thereâs not much sense of having this alpha and beta (and setting the target) if you are not to rotate around a target, is there?
Hey! Thanks, glad to be here.
For my purposes, Iâd like to rotate around a target but I disabled beta rotation simply because the camera panning axis is local and with beta rotation permitted, the y axis of the camera changes constantly. This interferes with the âscrollâ type interaction.
By default, the ArcRotateCamera has a mouse wheel input that will zoom when you try to scroll. If youâre looking to change that behavior, Iâd recommend first removing that and then adding an observer to the sceneâs onPointerObservable observable:
const mousewheel = camera.inputs.attached.mousewheel;
camera.inputs.remove(mousewheel);
scene.onPointerObservable.add((eventData) => {
const evt = eventData.event;
// This is just an arbitrary number that I'm using to control how quickly it moves
// This worked for me but YMMV
const wheelSensitivity = 1500;
const moveFactor = evt.deltaY / wheelSensitivity;
camera.inertialPanningY += moveFactor;
}, BABYLON.PointerEventTypes.POINTERWHEEL);
For smooth panning, you should add any deltas to the cameraâs inertialPanningX/Y variables and it will gradually move and slow down as it reaches its goal. You can also create your own custom inputs if you want to define more detailed behaviors. If you want to limit movement, you might need to add something to scene.onBeforeRenderObservable to check where your camera is and zero out the inertialPanningX/Y variable if it tries to go too far. For the keyboard, itâs pretty much the same except youâll increment on KEYDOWN.