Forum Discussion
Stjohn909
11 years agoHonored Guest
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.
5 Replies
Replies have been turned off for this discussion
- andrewtekMemberFollowing are some steps you can use to get your in-vehicle HMD working using Blueprints. First, check out the Vehicle template and notice how the in-car camera is configured.
1. You will notice that "use pawn control rotation" is false.
2. You will notice that "auto activate" is also false. Activation occurs when the event "Begin Play" occurs.
3. You will notice that "Begin Play" calls a blueprint function that performs the following actions:
a. Gets the controller.
b. Casts the controller to a PlayerController.
c. Gets the PlayerCameraManager for the PlayerController.
d. Sets the attribute "Follow Hmd Orientation" to true on the PlayerCameraManager.
e. Activates the camera.
The vehicle project template is pretty informative because it provides an example of a multi-camera pawn. It is pretty easy to simplify the example blueprint down to a single camera for general use.
Note, if you are using the latest version of 4.7, some of the BP nodes will look a little different than the template project... but it works. One benefit of this solution is that you will have one less thing running on each tick. - Stjohn909Honored GuestThanks andrewtek, This should help a lot.
Just so I'm clear, is this one of the vehicle templates included in the UE4 samples or is this one I would need to get from this site? Which one? I've been working with the Advanced Vehicle BP template that comes with UE4 and I had to add the HMD base offset BP in the pawn BP there as well.
cheers! - andrewtekMemberThe one I am talking about is the non-advanced vehicle blueprint template that comes with UE4.
- Stjohn909Honored GuestThanks, I'll give that a try.
- Jarrod84ProtegeIs it possible to see some shots of the full code ? {: I'm brand new to using unreal, and this is driving me nuts, this looks like the best answer but I'm not to sure in how to implement it.
Tanka
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 9 months ago
- 5 months ago
- 4 years ago