I’m working on a first person VR template for my future projects.
My player character has a belt attached to the z rotation of the HMD camera, but I have a annoying problem. If my “look down” angle (Y) is more than “-90” the game changes the “Z” and “X” rotation to 180° automatically and this rotates my belt “backwards”.
Already tried something like that, but there was still a “jump” in the rotation at the 90 degree peak.
(But I will try it again at home)
A other smaller problem is… if I change the relative “X” location, the game handles it like a world location and does not rotate it with the actor.
Is this a normal behavior, I thought the “relative” location should rotate with the actor?
Don’t attach belt to camera as a child component, keep camera and belt attached to the same parent component.
In Tick:
Take camera relative location, decrease Z (divide by two, for example) and use in Belt->SetRelativeLocation(…).
Extract yaw and UpVector from camera world rotation.
If UpVector.Z is equal to 0 - don’t update belt rotation in this frame.
If UpVector.Z is less then 0 - add 180 degrees to camera yaw, if it’s > 0 - keep camera yaw with no changes.
Then use Belt->SetWorldRotation(Roll = 0, Pich = 0, Yaw)
There is a blueprint example in RR for this for the holsters, however the basic premise is to Lerp from ForwardVector of the HMD to UpVector of the HMD depending on the dot product between ForwardVector and DesiredUp. To get the rotation you can MakeFromXZ with your new forward vector and the desired UpVector (+Z).
This way when you look straight down it uses the upvector of the HMD instead of the forward vector to prevent flipping it around (forward vector can now hover +/- within a buffer zone without causing incorrect rotation).
Extracting yaw by itself will end up with off by degree issues because the HMD can be rotated with roll AND yaw and you can get extra / less Yaw than your actual facing.
Hello, I have the same trouble to get floating item around my player in VR. I didn’t get anything of what you said and don’t have a clue on how to do it (I’m horrible at math) could you be a bit more specific on how to do it with blueprints ?