DeviceOrientationCamera not resetting to setTarget location

I have a scene rendered using DeviceOrientationCamera on Mobile and scene moves as the device orientation is changed.
I need to have camera looking at some specific position/angle at start based on device orientation at that point in time and move the scene relative to that initial point afterwords.
Issue : Camera is always placed at Y=0 irrespective of target I set with setTarget(…) method. As soon as attachControl is invoked camera target is reset and movement is always relative to Y=0 of the scene.
Can someone please help with the same.

Hello and welcome to the Babylon community! I’ll cc our camera pirate @PolygonalSun

Just to make sure that I’m understanding what you’re trying to do, I just want to confirm. Are you trying to get the camera to start at a specific location/angle and then get your device movements to start from that point? Furthermore, is there an expectation that the ground of your scene is not the same as the ground, with respect to your device’s position? The reason I’m asking is because it sounds like you’re trying to move relative to your viewpoint but the device’s IMU and the DeviceOrientationCamera are working in absolute angles (@RaananW feel free to correct me if I’m wrong). Working on this idea, when you attach your controls and the device starts listening to deviceorientation events, it will snap to the angle that your device is viewing at, rather than your camera. If this is in fact the case, you might be able to get things to work by modifying your camera’s upVector so that it thinks your relative “up” is the standard up to work from. At least, that’s the first thought that comes to mind.

1 Like

Thanks @PolygonalSun for the response.

  1. Are you trying to get the camera to start at a specific location/angle and then get your device movements to start from that point? : Yes
  2. Ground of the scene is same as ground.
    Just to explain usecase further, I am trying to create a scene that aligns with true north of the earth, as I move the device scene moves accordingly. With DeviceOrientationCamera, ground or up/down angle is correctly shown at start, if pointing below shows ground, if pointing above shows sky. Issue is with alpha angle Camera always starts from to 0, 0, 1 Vector irrespective of direction device is pointing to and the movement starts (with incorrect direction ref). I tried setting camera target from alpha angle of device, but as soon as attachDevice is called camera snaps to scene’s 0, 0, 1 again. I want it to point to 0, 1, 0 if device is pointing towards east.

No need to correct, this is correct :-). Device OrientationCamera gets the current rotation of the device as provided by the underlying system. If the system is not so precise, the rotation will be the same. It might drift as well over time.

You want your initial rotation around the Y axis to be set to look at a specific object.
This can be done with a transform node as a parent of the camera (is not supported directly in the camera).
You should also try using the resetToCurrentRotation function of the device orientation camera, though if I understand correctly it will do the exact opposite of what you want.