Get Head Location and Orientation in world space

I feel like I’m going insane. I’ve sat at this for far too long now and just can’t seem to get my head around what exactly the HMD functions are doing.

What I need exactly: Because we all know that 2D UI is horrible that’s not what we are doing. The idea was to simply use a small spotlight instead. We have a closed off room (can’t disappear because there’s always surfaces where the light will be visible), the size stays the same to the player no matter the distance and it’s directly projected onto objects removing all issues a 2D crosshair would have. Sounds simple enough? Well that’s where the issues start.

How the hell do I place that spotlight? I can’t simply attach it to the camera because the camera doesn’t follow the position of the HMD. It does copy the control rotation so that part is no issue luckily.

But how do I get the location of the HMD? For testing I’m using BP. In theory it should be simple enough.

So first up. There’s nothing directly returning the world position. Alright no biggie. Let’s just “Get Positional Tracking Camera Parameters” which has a “Camera Origin in world space”. Nice. Get that, add your HMD device position and the result is hundreds of units off.

Let’s try to add that to my position and add the device position on top of that. Nope again.

Is it just a relative position? Nope. Still wrong. Subtract device position from camera origin and feed that into the relative position and it’s still wrong.

The funny thing is just as the original attempt, the relative one and some others in between did yield the correct result when I positioned the HMD absolutely 100% correct. Usually quite far back.

Any help is greatly appreciated.

In case that’s of any interest or someone can get more information out of it than I do.

My camera socket has the spawn location of:

X=566, Y=-744, Z=197

The camera origin is:

X=121, Y=12, Z=6

And the Device Position is:

X=68, Y=10, Z=-5

All values rounded to ints but that doesn’t really matter does it?

Is it really that hard to get the exact location of the player head? Or am I just overlooking something obvious?

Cheers and thanks for reading (and maybe helping? : )

Have a look at this one and maybe try it out? It is a simple Pawn derived Blueprint.
This should make the ‘Sphere’ hover in front of your face. (I have an -20.0 on the Sphere’s X Transform here, and make sure it is small so you don’t get inside out culling).
HmdPos should then represent the position of the HMD.
Note I have not bothered with any orientation/rotation here.

Fredrum is HMD pos just an empty static mesh that you are pushing the position data to?

Yeah I mostly drag in cubes for my testing as I can visually see a bit more what goes on.
But beware of the temptation to scale the cube for visibility as it will affect transforms further down the component tree/dag

Ok so i added this to set a head collision before I was just scaling the z value of the hmd by 6 to bring up into eye level (bad workaround).

This works much better but I still experience some translation of my attached Sphere component when I lean to the sides. Have you noticed that as well?

No it sticks fine in my simple setup.
Are you looking at the ‘Sphere’ or the hmdPos when you see the sliding?
As remember that in my example I hadn’t added the hmd rotation and that would make the ‘Sphere’ slide when you angle your head around if you have the translation offset.
The ‘hmdPos’ object should still stick.

I just tried something like that. For some inexplicable reason it still doesn’t work.

That’s my setup right now. (oh yea and I’m also using a placeholder in front of the camera. Debugging a non visible object is beyond ridiculous :wink:

&stc=1

And that’s my ingame result:

[video]https://youtu.be/vOXZDEQzDoc[/video]

The head position is waay off.

The ball and the spotlight are childs of the camera. Not sure if that’s relevant but I’ve worked for quite some time only in World Space so it shouldn’t really matter. On top of that I’ve also tested a bit with rotation which seems to be correct. It’s just the position that’s completely off…

We have some driver issues on my PC with oculus and unreal. It has some display errors and massively worse performance. But the positional tracking and everything else works. Just not when I try to get the location apparently. Unreal is properly registering it.

Hmm…without knowing your entire setup its hard.
I would do a fresh minimal character blueprint like the one I have, and you too, with just that snippet and component hierarchy and nothing else.
And also maybe fresh character+camera controllers too just to be safe. And see if you get the same result. And then go from there?

I just also added the same rotation setup you are using there and that works ok in my minimal scene, the ball sits a meter in front of my nose even as I turn my head around.

Looks like you need to rotate/unrotate the vector.


Edit* make sure to set “follow HMD orientation” to true in your PlayerCameraManager

Just had an opportunity to test this. Indeed it was the issue that the vector is rotated. I am not entirely sure why that is and it somewhat feels counter intuitive but it’s solved now and works flawlessly!

Thanks a bunch everyone!

Erasio this is my set up and I still get drift from my collision sphere when I lean over to the sides. Basically like your basketball video. Can you share how you got it working?

I should have added in my post that you need to set “follow HMD orientation” to true in your PlayerCameraManager.

I have “follow HMD orientation” set in my playerCamManager as well as I do another set inside my character bp. I still have a lot of translation happening when I lean over to the sides, look up or down. Right now my setup is similar to my last setup but I am using SetWorldLocation&Rotation and Im getting the rotation of the hmd which works well I can see it rotate similarly to my rotation but the position is a bit off. Am I the only one running into this problem? here is a link i posted on imgur (the forum wouldnt let me post) http://i.imgur.com/eTWcpEN.png

Sorry. I wasn’t around the forum the last few days :S

My final result looks like this for the object:

&stc=1

And this for the crosshair itself:

&stc=1

I like this way

getHMDWorldPositionRotation.jpg

Using the above, I found this to be suitable (not the best as its just rotating the character on the Yaw, but it might good enough for others) - hope it helps.