Moving forward with device orientated camera and joysticks?

I have a project where I want to use a device orientated camera for rotation and also want to use a joystick for movement. The issue is when the device rotates the camera it’s not actually reflective of local space for the camera to pick up those changes:
https://www.babylonjs-playground.com/#C6V6UY#10 (You will need a laptop or gyro device to test)
When I move up on the joystick it moves along Z regardless of the orientation of the device camera. When it should move forward in the direction the cameras rotating.

Is there a fix to this? I don’t see how I can update the local space with the device camera properties.

This one is tricky. DeviceOrientationCamera uses camera.rotationQuaterion to handle its rotations except when there isn’t a gyro since it falls back to a normal FreeCamera. FreeCamera uses camera.rotation (Euler) to do rotations.

I iterated on this a few times with @syntheticmagus. Here is a nice solution that doesn’t involve angles at all: https://www.babylonjs-playground.com/#C6V6UY#15

1 Like

I will check this out as soon as I have time thanks so much!

1 Like