Closed chillbert closed 2 months ago
You can set the XR position with player, not sure yet how to just have it match the Canvas camera
const { player } = useXR();
player.position.z = 5;
Thanks, I didn't know useXR()... before I tried const { camera } = useThree(); but that is not available in VR/AR mode.
Isn't useXR a hook that should refresh itself? Since this is showing {"x":0,"y":0,"z":0}
even when I (the player right? walk around...
const { player } = useXR();
return <Text color={"red"}>{JSON.stringify(player.position)}</Text>
manually retrieving the player.position like this also didn't help.. it stays: 0
const { player } = useXR();
const [position, setPosition] = useState({ x: 0, y: 0, z: 0 });
useFrame((state, delta) =>{
setPosition({
x: player.position.x.toFixed(2), // Using toFixed for readability
y: player.position.y.toFixed(2),
z: player.position.z.toFixed(2)
});
})
Hello @chillbert, The player object represents the XR rig; the actual camera and controllers are children of this rig. These objects move relative to the rig when you move your HMD or controllers. When you teleport or use a joystick, you can move the rig itself so that everything moves together. To answer your question now, find the child object and get its position.
in v6 the "player rig" is now called the XROrigin. There's a tutorial to set the player origin (and this the player's start position) here https://docs.pmnd.rs/xr/tutorials/origin . This can also allow to mount the origin to a different object so that the player moves in relation to this object.
If something is unclear feel free to reopen :)
Is there a way to set the camera position when AR session is starting? Preferably to the same as the non-AR session position. In this example I am setting the camera 2 units in front of the model (0,0,0) - in the non-AR session it looks good, as soon as I start the AR, the camera jumps to 0,0,0.