Shifting VRPOV from player to VRBoids

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 :・゚✧ , you can view the demo here:

1 Like

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


syntax for accessing child is ._children yes?

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

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

the camera is here


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

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

I love your dev log! Keep it coming

1 Like

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];

Now, I am trying to figure out how to switch the player’s POV into this 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…

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

Why do you need more than one XR camera?

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?

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

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

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

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 :slight_smile:

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

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.