Starting position of FreeCamera after animation is wrong

I start several sequences of animation. Then start the first position from the beginning. In this case the FreeCamera starts correctly at the first position:

.....
      var camera = new FreeCamera("freeCamera", camStartPosition, scene);
      camera.setTarget(camTarget);
      scene.activeCamera = camera;
      setCamera(scene.activeCamera!);

movingInSpace: () => {
camera.position = camStartPosition;
      camera.setTarget(camTarget);

      let cam = camera;

      var speed = 45;
      var frameCount = 200;
      var ease = new CubicEase();
      ease.setEasingMode(EasingFunction.EASINGMODE_EASEINOUT);

      var targetEndPos_pic0 = new Vector3(allPics.pic0.x, allPics.pic0.y, allPics.pic0.z);
      var camEndPos_pic0 = new Vector3(allPics.pic0.x, allPics.pic0.y, 0.0);
      Animation.CreateAndStartAnimation('at1', cam, 'position', speed, frameCount, cam.position, camEndPos_pic0, 0, ease);
      Animation.CreateAndStartAnimation('at2', cam, 'target', speed, frameCount, cam.target, targetEndPos_pic0, 0, ease);
      
      var targetEndPos_pic1 = new Vector3(allPics.pic1.x, allPics.pic1.y, allPics.pic1.z);
      var camEndPos_pic1 = new Vector3(allPics.pic1.x, allPics.pic1.y, 0.0);
      setTimeout(() => {
        Animation.CreateAndStartAnimation('at1', cam, 'position', speed, frameCount, cam.position, camEndPos_pic1, 0, ease);
        Animation.CreateAndStartAnimation('at2', cam, 'target', speed, frameCount, cam.target, targetEndPos_pic1, 0, ease);
      }, 3000);

....

But if I rotate the scene and then start animation, then
the first start position of camera is different and wrong.
What could be the reason?
How do I reset the camera?

Could you repro in the playgrround as this would definitely help the community trying to figure out what is happening ?

ok, in playground works (start, rotate manually again starts):
https://playground.babylonjs.com/#8LFTCH#829
It does not work similar code but with deviceSourceManager an react native n android:

 var camera = new FreeCamera("freeCamera", camStartPosition, scene);
      camera.setTarget(camTarget);
      scene.activeCamera = camera;
      setCamera(scene.activeCamera!);
      // scene.createDefaultLight(true);

      // This creates a light, aiming 0,1,0 - to the sky (non-mesh)
      var light = new HemisphericLight("light", new Vector3(1, 3, 1), scene);

      // Default intensity is 1. Let's dim the light a small amount
      light.intensity = 0.7;

      const rootNode = new TransformNode('Root Container', scene);
      setRootNode(rootNode);

      const deviceSourceManager = new DeviceSourceManager(engine);
      const handlePointerInput = (inputIndex: PointerInput, previousState: Nullable<number>, currentState: Nullable<number>) => {
        if (inputIndex === PointerInput.Horizontal &&
          currentState && previousState) {
          rootNode.rotate(Vector3.Down(), (currentState - previousState) * 0.005);
        };
      };

      deviceSourceManager.onDeviceConnectedObservable.add(device => {
        if (device.deviceType === DeviceType.Touch) {
          const touch: DeviceSource<DeviceType.Touch> = deviceSourceManager.getDeviceSource(device.deviceType, device.deviceSlot)!;
          touch.onInputChangedObservable.add(touchEvent => {
            handlePointerInput(touchEvent.inputIndex, touchEvent.previousState, touchEvent.currentState);
          });
        } else if (device.deviceType === DeviceType.Mouse) {
          const mouse: DeviceSource<DeviceType.Mouse> = deviceSourceManager.getDeviceSource(device.deviceType, device.deviceSlot)!;
          mouse.onInputChangedObservable.add(mouseEvent => {
            if (mouse.getInput(PointerInput.LeftClick)) {
              handlePointerInput(mouseEvent.inputIndex, mouseEvent.previousState, mouseEvent.currentState);
            }
          });
        }
      });
      
      const transformContainer = new TransformNode('Transform Container', scene);
      transformContainer.parent = rootNode;
      // transformContainer.scaling.scaleInPlace(0.2);
      transformContainer.position.y = - 1.0;

Are you using Babylon Native ? if yes smthg might be missing at the input level ?

@Cedric or @PolygonalSun might be able to help on this front

The problem: if I don’t turn manually, everything starts from the right position.
However, if I rotate by touch on android and then start Animation, then I am shown the wrong start.

@igorroman777

Can you repro the issue with Babylon Native (without react) ? Does it repro with playground on Windows?
Being able to repro on BN/Windows without react will help us track down the issue.

1 Like

it is probably due to rootNode: :smiley:
How can these be reset or better used as a camera?

   const rootNode = new TransformNode('Root Container', scene);
   setRootNode(rootNode);

      const deviceSourceManager = new DeviceSourceManager(engine);
      const handlePointerInput = (inputIndex: PointerInput, previousState: Nullable<number>, currentState: Nullable<number>) => {
        if (inputIndex === PointerInput.Horizontal &&
          currentState && previousState) {
          rootNode.rotate(Vector3.Down(), (currentState - previousState) * 0.005);

        };
      };

Yes, using the camera.rotation in DeviceSourceManager instead of rootNode.rotate works

2 Likes