# Starting position of FreeCamera after animation is wrong

**URL:** <https://forum.babylonjs.com/t/starting-position-of-freecamera-after-animation-is-wrong/23471>\
**Category:** Questions\
**Tags:** camera\
**Created:** [August 31, 2021, 5:45pm UTC](https://forum.babylonjs.com/t/starting-position-of-freecamera-after-animation-is-wrong/23471 "2021-08-31T17:45:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![igorroman777](https://avatars.discourse-cdn.com/v4/letter/i/b4bc9f/32.png) [@igorroman777](https://forum.babylonjs.com/u/igorroman777)\
**Post date:** [August 31, 2021, 5:45pm UTC](https://forum.babylonjs.com/t/starting-position-of-freecamera-after-animation-is-wrong/23471/1 "2021-08-31T17:45:03Z")

</div>

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:

```auto
.....
      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?**

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [August 31, 2021, 6:56pm UTC](https://forum.babylonjs.com/t/starting-position-of-freecamera-after-animation-is-wrong/23471/2 "2021-08-31T18:56:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![igorroman777](https://avatars.discourse-cdn.com/v4/letter/i/b4bc9f/32.png) [@igorroman777](https://forum.babylonjs.com/u/igorroman777)\
**Post date:** [August 31, 2021, 8:43pm UTC](https://forum.babylonjs.com/t/starting-position-of-freecamera-after-animation-is-wrong/23471/3 "2021-08-31T20:43:05Z")

</div>

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

```auto
 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;

```

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [August 31, 2021, 8:49pm UTC](https://forum.babylonjs.com/t/starting-position-of-freecamera-after-animation-is-wrong/23471/4 "2021-08-31T20:49:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![igorroman777](https://avatars.discourse-cdn.com/v4/letter/i/b4bc9f/32.png) [@igorroman777](https://forum.babylonjs.com/u/igorroman777)\
**Post date:** [August 31, 2021, 8:55pm UTC](https://forum.babylonjs.com/t/starting-position-of-freecamera-after-animation-is-wrong/23471/5 "2021-08-31T20:55:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [September 1, 2021, 12:12pm UTC](https://forum.babylonjs.com/t/starting-position-of-freecamera-after-animation-is-wrong/23471/6 "2021-09-01T12:12:14Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![igorroman777](https://avatars.discourse-cdn.com/v4/letter/i/b4bc9f/32.png) [@igorroman777](https://forum.babylonjs.com/u/igorroman777)\
**Post date:** [September 1, 2021, 5:20pm UTC](https://forum.babylonjs.com/t/starting-position-of-freecamera-after-animation-is-wrong/23471/7 "2021-09-01T17:20:03Z")

</div>

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

```auto
   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);

        };
      };

```

---

<div class="post-metadata">

**Author:** ![igorroman777](https://avatars.discourse-cdn.com/v4/letter/i/b4bc9f/32.png) [@igorroman777](https://forum.babylonjs.com/u/igorroman777)\
**Post date:** [September 1, 2021, 7:02pm UTC](https://forum.babylonjs.com/t/starting-position-of-freecamera-after-animation-is-wrong/23471/8 "2021-09-01T19:02:44Z")

</div>

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