AdaRoseCannon / aframe-xr-boilerplate

Get started quickly with VR and AR using AFrame
https://aframe-xr-starterkit.glitch.me/
MIT License
110 stars 20 forks source link

Simple Navmesh Contraint: #cameraRig entity position #2

Closed CrowtreesStudio closed 2 years ago

CrowtreesStudio commented 2 years ago

Regarding the #cameraRig and #camera setup. The code ignores the #cameraRig positioning and instead will send the #camera to the world 0, 0, 0 coordinates. The #cameraRig positioning therefore has no effect on placing the camera in desirable spot in the scene.

AdaRoseCannon commented 2 years ago

The worldToLocal function sets the offset to be relative to the cameraRig. If you open devtools and move the camera rig you will see that the camera moves with it.

https://github.com/AdaRoseCannon/aframe-xr-boilerplate/blob/glitch/simple-navmesh-constraint.js#L92

CrowtreesStudio commented 2 years ago

Yes this is true but try entering a position for the cameraRig in the code and see what happens. I have the camera back at the 0, 0 , 0 position but with an offset relative to where I position the cameraRig. E.G. cameraRig position 4, 0, 4 and camera position becomes -4, 0, -4.

Interesting if I'm the only one experiencing this :D

AdaRoseCannon commented 2 years ago

Running

document.getElementById('cameraRig').object3D.position.set(0,0,1)

on https://aframe-xr-starterkit.glitch.me/

Works as expected for me

AdaRoseCannon commented 2 years ago

Although if I try to move the rig off the navmesh it moves the camera back to where it was the frame before which is the expected behavior. Check to make sure the camera is placed so that the simple-navmesh component can see your navmesh.

CrowtreesStudio commented 2 years ago

I tried out the glitch with the following: <a-entity position="-15 0 15" rotation="0 0 0" origin-on-ar-start id="cameraRig"> The camera remained where it was(I tried smaller numbers first). The rotation works because I used that to make sure the file was updating correctly.

AdaRoseCannon commented 2 years ago

On the camera ensure it starts off above the navmesh. Set it's fall to a large number like 10 and height to 0. You should have the camera fall all the way to floor and then you should be able to move it and the camera rig as you please.

simple-navmesh-constraint="navmesh:#navmesh-el;fall:10;height:0;"

CrowtreesStudio commented 2 years ago

I think I've confused the conversation. I'm making adjustments to the cameraRig position in the index.html file to start the camera off in a more desirable position in the scene. This I was lead to understand is more desirable than changing the camera position directly especially if you want to change it's height.

Straight out of the A-Frame box, the cameraRig positioning works correctly and the camera moves with it. Adding the simple-navMesh-constraint, the camera stubbornly remains at the world origin with the cameraRig's position having no effect on it.

I apologize for taking up so much of your time on this and do appreciate the work you've put into the boiler plate.

AdaRoseCannon commented 2 years ago

Do you have a navmesh in your scene? The behavior you are getting is what happens when the component cannot find the navmesh.

CrowtreesStudio commented 2 years ago

I do have a navmesh and the camera is constrained as expected using the WASD keys to navigate the scene.

I cannot change the start position for the player using the cameraRig, the camera will always start at position 0, 1.65, 0, no matter what the cameraRig position indicates (see above A-Frame mark-up snippet).

AdaRoseCannon commented 2 years ago

It is really odd that I cannot reproduce it.

CrowtreesStudio commented 2 years ago

The Glitch link you provide above behaves just like my local file when you change the cameraRig position in the index.html file (screenshot below).

Screen Shot 2022-03-17 at 1 44 31 PM

The camera remains fixed to the position="0 1.65 0" no matter what position you assign the cameraRig. It has me flummoxed.

AdaRoseCannon commented 2 years ago

I think the i've identified the issue, it should now hopefully behave fine.

Weirdly my behaviour was also broken but differently, it would always fail the first hit which would place the user at 0.4 of the way because the next hit would work.

Now if the first hit fails it leaves the user where they started rather than moving them towards the origin until it works.

AdaRoseCannon commented 2 years ago

I only noticed it because I tried to place the camera into an entire other room and I knew how big the building was that the amount the camera had moved was only half of what it should be.

CrowtreesStudio commented 2 years ago

Yes, that fixed it :D Thank you

AdaRoseCannon commented 2 years ago

Great, thanks so much for your patience!