# Is there a way to animate arcRotateCamera by target and position?

**URL:** <https://forum.babylonjs.com/t/is-there-a-way-to-animate-arcrotatecamera-by-target-and-position/49694>\
**Category:** Questions\
**Tags:** animation, camera\
**Created:** [April 15, 2024, 11:13pm UTC](https://forum.babylonjs.com/t/is-there-a-way-to-animate-arcrotatecamera-by-target-and-position/49694 "2024-04-15T23:13:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tawibox](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tawibox/32/22881_2.png) [@tawibox](https://forum.babylonjs.com/u/tawibox)\
**Post date:** [April 15, 2024, 11:13pm UTC](https://forum.babylonjs.com/t/is-there-a-way-to-animate-arcrotatecamera-by-target-and-position/49694/1 "2024-04-15T23:13:15Z")

</div>

Hey community,

Is there a way we can apply animation data to an ArcRotateCamera’s `target` and `position` directly by any chance?

For example, if I load in two sets of animation data from a .gltf, and I want to apply one set to “target” of the camera while apply another set to “position” of an camera? Also, I hope the camera type should be `ArcRotateCamera` since I need to control the radius of the camera after.

From the test I have so far, if I use for example `scene.cameras[i].target = ...`, I can update the camera dynamically right away which is great. But when I use `scene.cameras[i].position = ...`, the position won’t change dynamically until I call the `rebuildAnglesAndRadius()` function. But in this case I wont be able to animate the position in real-time. PS: I have also tried `setPosition` and `setTarget` and seems not working.

Any good solutions?

My PG:

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#WUYDVT%23125)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Many thanks!  
Tawibox

---

<div class="post-metadata">

**Author:** ![inteja](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/inteja/32/22553_2.png) [@inteja](https://forum.babylonjs.com/u/inteja)\
**Post date:** [April 16, 2024, 2:43am UTC](https://forum.babylonjs.com/t/is-there-a-way-to-animate-arcrotatecamera-by-target-and-position/49694/2 "2024-04-16T02:43:29Z")

</div>

For target you can simply use something like:

```auto
const targetPosition = Vector3.Lerp(startPosition, endPosition, lerpAmount);
camera.setTarget(targetPosition, undefined, false, true);

```

For position, given it’s an arc rotate camera, you’re better off interpolating `alpha`, `beta` and `radius`, because together these properties determine position.

---

<div class="post-metadata">

**Author:** ![MeshSlayer](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@MeshSlayer](https://forum.babylonjs.com/u/MeshSlayer)\
**Post date:** [April 16, 2024, 9:39am UTC](https://forum.babylonjs.com/t/is-there-a-way-to-animate-arcrotatecamera-by-target-and-position/49694/3 "2024-04-16T09:39:12Z")

</div>

ArcRotateCamera is native to BabylonJS, your unreal camera is imported as FreeCamera.

After looking at the hierarchy of your scene, I noticed that you unreal camera is nested under some nodes and you’re animating the nodes rather than the camera object.

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/1/712c9033bef26ef9e4db98507fb2bb92610277d4.png)

 ![Screenshot 2024-04-16 at 10.26.22](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/2/0/206fcffb1a33acb5b668fa41dc708f79bc7b3782.png)

if you want to use ArcRotateCamera, you need to write some custom code to convert these animation to `alpha`, `beta` and `radius`  
else you can use a FreeCamera, but you need to take the parenting into consideration in order to figure out the correct `position` and `rotation` values

Also, just saying, scaling the camera is a bad practice.

Good luck.

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [April 16, 2024, 9:51am UTC](https://forum.babylonjs.com/t/is-there-a-way-to-animate-arcrotatecamera-by-target-and-position/49694/4 "2024-04-16T09:51:44Z")

</div>

Probably this thread may help - [How to build animation for ArcRotateCamera so it can rotate smoothly](https://forum.babylonjs.com/t/how-to-build-animation-for-arcrotatecamera-so-it-can-rotate-smoothly/25698)

---

<div class="post-metadata">

**Author:** ![tawibox](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tawibox/32/22881_2.png) [@tawibox](https://forum.babylonjs.com/u/tawibox)\
**Post date:** [April 16, 2024, 8:38pm UTC](https://forum.babylonjs.com/t/is-there-a-way-to-animate-arcrotatecamera-by-target-and-position/49694/5 "2024-04-16T20:38:40Z")

</div>

@MeshSlayer Thank you for the response!

ah you are right. the camera node itself doesnt contains animations while the higher level transform nodes have.

Is any way I can consolidate the nested transforms and bake the final result in one camera node?

Tawibox
