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.