Oculus Rift Separate View

From Epic Wiki
Jump to: navigation, search



By default, using an Oculus Rift in Unreal Engine 4 affects the rotation responsible for both the players view and movement direction.

There are two main ways to change this:

  • Creating a Player Camera Manager, Player Controller & GameMode using Blueprints.
  • Creating a new Player Controller, Character & GameMode in C++.

The end results are similar - the players view and movement directions are separate - but the C++ version is more flexible.


  1. Create a Blueprint that based on PlayerCameraManager.
  2. In the Defaults tab, find "Follow Hmd Orientation" and set it to "true".
  3. Create a Blueprint that based on PlayerController.
  4. In the Defaults tab, find Player Camera Manager Class and set it to your PlayerCameraManager Blueprint.
  5. Create a Blueprint that based on GameMode.
  6. In the Defaults tab, find Default Controller Class and set it to your PlayerController Blueprint.
  7. Finally, under your levels World Settings, find GameMode Override and set it to your GameMode Blueprint.


The C++ method is a more complex, but is also more flexible.


Add HeadMountedDisplay to PublicDependencyModuleNames.

        PublicDependencyModuleNames.AddRange(new string[] { 


    virtual void UpdateRotation(float DeltaTime) override;
    UFUNCTION(BlueprintCallable, Category="Pawn")
    FRotator GetViewRotation() const;

    UFUNCTION(BlueprintCallable, Category="Pawn")
    virtual void SetViewRotation(const FRotator& NewRotation);
    virtual void SetControlRotation(const FRotator& NewRotation) override;

     *  View & Movement direction are now separate.
     *  The controller rotation will determine which direction we will move.
     *  ViewRotation represents where we are looking.
    FRotator ViewRotation;


// Make sure you include this!!
#include "IHeadMountedDisplay.h"

void AYourPlayerController::UpdateRotation(float DeltaTime)
    // Calculate Delta to be applied on ViewRotation
    FRotator DeltaRot(RotationInput);

    FRotator NewControlRotation = GetControlRotation();

    if (PlayerCameraManager)
        PlayerCameraManager->ProcessViewRotation(DeltaTime, NewControlRotation, DeltaRot);


    if (!PlayerCameraManager || !PlayerCameraManager->bFollowHmdOrientation)
        if (GEngine->HMDDevice.IsValid() && GEngine->HMDDevice->IsHeadTrackingAllowed())
            FQuat HMDOrientation;
            FVector HMDPosition;

            // Disable bUpdateOnRT if using this method.
            GEngine->HMDDevice->GetCurrentOrientationAndPosition(HMDOrientation, HMDPosition);

            FRotator NewViewRotation = HMDOrientation.Rotator();

            // Only keep the yaw component from the controller.
            NewViewRotation.Yaw += NewControlRotation.Yaw;
    APawn* const P = GetPawnOrSpectator();
    if (P)
        P->FaceRotation(NewControlRotation, DeltaTime);

void AYourPlayerController::SetControlRotation(const FRotator& NewRotation)
    ControlRotation = NewRotation;
    // Anything that is overriding view rotation will need to 
    // call SetViewRotation() after SetControlRotation().
    if (RootComponent && RootComponent->bAbsoluteRotation)

void AYourPlayerController::SetViewRotation(const FRotator& NewRotation)
    ViewRotation = NewRotation;

FRotator AYourPlayerController::GetViewRotation() const
    return ViewRotation;


    virtual FRotator GetViewRotation() const override;


FRotator AYourCharacter::GetViewRotation() const
    if (AYourPlayerController* MYPC = Cast<AYourPlayerController>(Controller))
        return MYPC->GetViewRotation();
    else if (Role < ROLE_Authority)
        // check if being spectated
        for (FConstPlayerControllerIterator Iterator = GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator)
            APlayerController* PlayerController = *Iterator;
            if (PlayerController && PlayerController->PlayerCameraManager->GetViewTargetPawn() == this)
                return PlayerController->BlendedTargetViewRotation;

    return GetActorRotation();


AYourGameMode::AYourGameMode(const class FPostConstructInitializeProperties& PCIP)
    : Super(PCIP)
    DefaultPawnClass = AYourCharacter::StaticClass();
    PlayerControllerClass = AYourPlayerController::StaticClass();

See also