UniversalCamera No longer rotates from touch?

If you go into your console in chrome and turn on the phone emulation when going to this scene:
Everything works.

but if you change the camera from a free camera to a UniversalCamera everything stops working with touch controls.

@Cedric do you mind having a look?

@Deltakosh Sure! I’m on it

1 Like


Mouse events show up in the console but it doesn’t seem that’s it’s touch event. Not sure about that.
I’ve tried the PG on my device and I can zoom in/out but I can’t do it with Chrome emulation.
Is there an option to enable touch emulation?

Its also proven to not work on mobiles though not just emulation, only reason I figured it out is because clients were complaining that they could not rotate the camera on mobile.

ok, I’m continuing my investigation.

I appreciate you!

1 Like

It’s a bit more clear.

On this line :

hostInformation.isMobile is false when starting on a desktop webbrowser. It’s only updated when creating the Canvas. So, in order to get it to True, click the Run button to restart the playground and it should work.

And with that, I get the same behavior as on my device.

Let me know how it goes for you.

With doing that the touches seem to move the camera, but not in a predictable way or in a manor that allows you to rotate.

Doing the refresh did get them to at least register though, but I can confidently say the UniversalCamera is not controllable with touch.

What you have shown though makes me wonder. I might have to dig in now and look.

Maybe @PolygonalSun knows more about touch input :slight_smile:

1 Like

Yeah its really screwy its like it does not want to rotate, but does want to move forward.

@PolygonalSun maybe this should use the pointer prefix for the isMouse ?

@sebavan, are you referring to making use of the eventPrefix value in the InputManager (which is propagated by Tools.GetPointerPrefix(engine))? If so, I’m not sure that would work for the this scenario.

In any case, lemme take a look at the code and see what’s going on with the Universal Camera


perfect !!!

So here’s what I found. The reason that the UniversalCamera is failing to rotate when in emulation is because of a set boolean in the TouchCamera (which is inherited by UniversalCamera).

Because the path of inheritance looks like this:
Camera -> TargetCamera -> FreeCamera (default for PG) -> TouchCamera -> UniversalCamera
And the affected change is in the TouchCamera, this should explain why it works in the default PG but not when the camera is changed to UniversalCamera.

The fix for this would either be to remove the mouse.touchEnabled = false line from TouchCamera

Or add a flag to line 73 of freeCameraMouseInput.ts that accounts for emulators:

keep in mind its more then emulation. It did not on the phone really either. If you have a mobile client you can test it on try https://playground.babylonjs.com/#0XYMA9#41

I can confirm that UniversalCamera touch events don’t work on iPhones and iPads (at least mine). But, by adding:

camera.inputs.attached.mouse.touchEnabled = true;

right after creating the camera, my mobile devices work again.


Aye now we are getting to the meat and pudding!

@PolygonalSun a PR would be awesome if we can automate it ?

@sebavan, sorry about the delay in response here but would you be able to clarify on what you mean?