Quick and dirty HMD base orientation in UE4
Hopefully this can help somebody, because it drove me nuts.
For the longest time, I could not figure out how to get my HMD to move with a vehicle, any vehicle. With "Follow HMD Orientation" turned on anywhere in any component, the HMD would always be facing world X, and not re-orienting with rotation updates to the root component. This persisted through many versions of UE4, but I think I was able to brute force it into working.
I started with the C++ Flying Pawn template and called the project FlyingVR2>
First I added "HeadMountedDisplay" to the list of module deps in FlyingVR2.Build.cs
Then in FlyingVR2Pawn.cpp I made this change to the constructor:
Then in the Tick, I added this snippet:
Please bear in mind that I am really not good at C++, and probably wasn't able to understand the proper fix from the numerous code examples offered by Kris, Rama, and others, but this method was the only thing that worked for me.
I found a way to do the same thing in BP, but there's an extra function in BP that I couldn't find in C++ that offsets the HMD base orientation rather than sets it.
For the record, this is the Oculus fork, branch 4.7-np.
For the longest time, I could not figure out how to get my HMD to move with a vehicle, any vehicle. With "Follow HMD Orientation" turned on anywhere in any component, the HMD would always be facing world X, and not re-orienting with rotation updates to the root component. This persisted through many versions of UE4, but I think I was able to brute force it into working.
I started with the C++ Flying Pawn template and called the project FlyingVR2>
First I added "HeadMountedDisplay" to the list of module deps in FlyingVR2.Build.cs
Then in FlyingVR2Pawn.cpp I made this change to the constructor:
Camera->bUsePawnControlRotation = true; // rotate camera with controller
Then in the Tick, I added this snippet:
// Rotate HMD -- I have to do this because the HMD base doesn't stick itself to the vehicle by default.
if (GEngine->HMDDevice.IsValid())
{
FQuat HMDOrient(GEngine->HMDDevice->GetBaseOrientation());
FQuat PawnOrient(this->GetActorQuat());
HMDOrient = FQuat::Slerp(PawnOrient.Inverse(), HMDOrient, DeltaSeconds);
GEngine->HMDDevice->SetBaseOrientation(HMDOrient);
}
Please bear in mind that I am really not good at C++, and probably wasn't able to understand the proper fix from the numerous code examples offered by Kris, Rama, and others, but this method was the only thing that worked for me.
I found a way to do the same thing in BP, but there's an extra function in BP that I couldn't find in C++ that offsets the HMD base orientation rather than sets it.
For the record, this is the Oculus fork, branch 4.7-np.
