Help to a babylon newcomer!) zoomToMouseLocation speed changes after reseting target

Hey guys, hope you can help me on this one.

I used a new Babylon.js 5 feature camera.zoomToMouseLocation. It works as expected until I zoom to the mesh(change camera target and radius). Zoom speed becomes significantly faster(Sometimes after the second zoom). And sometimes zoom out starts to work slowly, but the actual camera radius changes, I can see that after camera rotation, the camera reposition is far from the origin before rotation.

I found the function, that I think is responsible for the behavior _zoomToMouse. I think changing the target here may cause the issue vec.subtract( as the target is new.

I have a lack of math knowledge, so would be very grateful if somebody could explain to me what’s happening.

Here’s the working example

cc @PolygonalSun if you can have a look ?

@clovett I would be very grateful if you help me with this one.
I found that zoom works well if the target is 0, 0, 0. But if you set it to 100, 100, 100 for example and change the radius then this variable values let directionToZoomLocation = vec.subtract(; becomes much bigger. I think this is an issue, but can’t come with as solution.
How can I overcome this?

First off, welcome to the community @ci4anish! I am able to repro the type of behavior that you’re seeing though I’m not 100% sure as to the logic myself. It looks like the target is moving around pretty wildly. I’m not going to be in the office for a few days so if there’s no resolution on this, I’ll take a look when I get back and see what I can do.

Thanks, @PolygonalSun. Much appreciated!

+1… :pray:

Thanks in advance

cc @RaananW if he has a spare cycle to look into it ?

Seems like we are missing a single normalize call :slight_smile:

Is that better - zoomToMouseLocation issue after reseting target | Babylon.js Playground ( ?

1 Like

Here is the fix - Arc rotate zoom to mouse - reuse vectors, normalize direction by RaananW · Pull Request #12093 · BabylonJS/Babylon.js (

1 Like

@RaananW unfortunately no. Now you’re not zooming to the mouse location

Looking into that. Thanks!

That was a bit trickier - [ZoomToMouse] when changing radius and target, hit plane was incorrect by RaananW · Pull Request #12102 · BabylonJS/Babylon.js (

The issue ws the hit plane that was incorrectly calculated. notice that in certain cases it will feel a bit off, as the target will be set in the middle of the sphere-array and not a specific array. The target changes on each frame, so this is an expected side-effect.


@RaananW Seems like it’s working, thanks! When to expect this in @babylon/core package do you know?

it’s already in 5.0.0-rc.2, should work in @babylon/core as well from this version