# Shifting VRPOV from player to VRBoids

**URL:** <https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657>\
**Category:** Questions\
**Created:** [June 12, 2020, 11:32pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657 "2020-06-12T23:32:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 12, 2020, 11:32pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/1 "2020-06-12T23:32:01Z")

</div>

Hi There,

I am trying to shift my camera (position, orientation) in VR from the player’s head into the POV of one of the floating boids in the environment, but I see to be stuck. (1.) I’m pretty sure that I’ve made each boid a parent of a camera, but when I console log boid.child (I get undefined) and (2.) I’m not sure how to “redefine” the camera, can I just re-assign it: //camera = models[0].camera; or is there some XR magic that I’m not comprehending (/not getting a frame of reference for). All my code is here: [Glitch :･ﾟ✧](https://glitch.com/edit/#!/babylonboidsvr?path=index.html%3A497%3A36) , you can view the demo here: [https://babylonboidsvr.glitch.me/](https://babylonboidsvr.glitch.me/)

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 12, 2020, 11:33pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/2 "2020-06-12T23:33:08Z")

</div>

I’m now thinking I’m getting undefined due to a scope issue…

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 12, 2020, 11:35pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/3 "2020-06-12T23:35:21Z")

</div>

maybe…

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 12, 2020, 11:41pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/4 "2020-06-12T23:41:45Z")

</div>

syntax for accessing child is .\_children yes?

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 12, 2020, 11:43pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/5 "2020-06-12T23:43:02Z")

</div>

ok so why doesn this line camera = models[0].\_children; change the camera from the player to the boid’s perspective?

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 13, 2020, 5:34am UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/6 "2020-06-13T05:34:41Z")

</div>

I think some kind of “secret camera” is being created here

```
    // enable xr
    const xr = await scene.createDefaultXRExperienceAsync({
      floorMeshes: [ground]
    });

```

or, an XR camera, and I have to figure out how to access it and manipulate it

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 13, 2020, 5:47am UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/7 "2020-06-13T05:47:04Z")

</div>

the camera is here

```
    console.log(xr.baseExperience.camera);

```

now, I’m trying to set it to basically just have the same position/orientation as the boid camera

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 13, 2020, 11:17pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/8 "2020-06-13T23:17:47Z")

</div>

now I am trying to figure out how to add multiple XR cameras and then shift between them…

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [June 15, 2020, 4:53pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/9 "2020-06-15T16:53:41Z")

</div>

I love your dev log! Keep it coming

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 15, 2020, 11:28pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/10 "2020-06-15T23:28:52Z")

</div>

I believe I have one xrcamera, which is a child of one boid

```
    function initBoids() {
      boxes = loadCubes(20); 
      const xrCamera = new BABYLON.WebXRCamera("boidPOV", scene, xr.baseExperience.sessionManager);
      xrCamera.parent = models[0];
              }
    xr.baseExperience.sessionManager.onXRSessionInit.add(initBoids);

```

Now, I am trying to figure out how to switch the player’s POV into this camera.

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 15, 2020, 11:35pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/11 "2020-06-15T23:35:53Z")

</div>

```
      xr.baseExperience.camera = xrCamera;

```

I think that this puts me into the POV of the boid for one frame;  
so, I guess I have to figure out how to continually update this…  
or update the camera’s position…

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 15, 2020, 11:52pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/12 "2020-06-15T23:52:14Z")

</div>

@Deltakosh oof, could use a nudge here… not sure why in VR the paired camera only pairs for a frame, whereas when I run this not in VR, the camera tracks the boid’s POV just fine…

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [June 16, 2020, 6:10am UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/13 "2020-06-16T06:10:59Z")

</div>

Why do you need more than one XR camera?

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 16, 2020, 7:29pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/14 "2020-06-16T19:29:12Z")

</div>

I mean… do I? Can I shift the POV of the player into a regular camera (attached to a boid) once I’ve entered XR mode? I thought that regular cameras are out of play once you’re in XR mode?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [June 16, 2020, 7:29pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/15 "2020-06-16T19:29:51Z")

</div>

What exactly do you want to do? have viewer-mode in webxr?

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 16, 2020, 9:30pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/16 "2020-06-16T21:30:48Z")

</div>

I basically want a regular VR set up where you can walk around and look at things, but then I want to be able to press a button, and look directly through point of view of one of the boids that are flying around in the environment. I am trying to create a vr game where one of your powers is to look through the eyes of these flying robots that follow you. When you go to this sketch I made: [https://babylonboidsunicam.glitch.me/](https://babylonboidsunicam.glitch.me/) you can use the inspector to flick into the POV of any boid. I want to do that, but in VR, and then I want to be able to shift back into the player perspective.

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 16, 2020, 9:31pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/17 "2020-06-16T21:31:15Z")

</div>

I’m not sure exactly how to achieve that, so I’m just trying different things, until I stumble upon the solution.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [June 17, 2020, 7:00am UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/18 "2020-06-17T07:00:09Z")

</div>

I guess you only need one camera for this. just as you change the position and rotation of the robots, you can change the position and rotation of the XR camera. it is a node and works the same.  
I have to admit that I haven’t tested constant position change (which requires a teleportation cal on each frame( but the XR specs are very specific about this action being very cheap because it might be called on each frame.

Give it a try! I honestly think that this kind of movement is not for VR-beginners (losing orientation very quickly if you don’t have a lot of points of reference and if you move very fast), but there are a few games and experiences that do that, and they seem to be working well 🙂

---

<div class="post-metadata">

**Author:** ![saitogroup](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/saitogroup/32/10624_2.png) [@saitogroup](https://forum.babylonjs.com/u/saitogroup)\
**Post date:** [June 18, 2020, 9:48pm UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/19 "2020-06-18T21:48:25Z")

</div>

Hi, thank you so much… OK… so what I am going to try is going to be making the xr camera a child of a boid, and if that doesn’t work automatically, then I’m going to look on doing that and I guess adding a teleportation call on each frame as you suggested

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [June 19, 2020, 7:38am UTC](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657/20 "2020-06-19T07:38:17Z")

</div>

Awesome! Just wanted to say - I am about to implement something similar for movement in the scene when I find the time for it, will be great to hear about your experience.

[Next page](https://forum.babylonjs.com/t/shifting-vrpov-from-player-to-vrboids/11657.md?page=2)
