How do you all manage character head movement?

I’ve been looking through sources online about how to manage player head moment for a couple of days now and I can’t seem to manage to find a concrete solution anywhere. By head movement, I mean the player moving their actual head through the axis and it translating ingame to head movement of the character. I’ve seen a number of ways people have gone about doing it including just moving and attaching the camera directly to the player’s head itself. Being very new to 3D game development in general I’m not entirely sure what the best way to do would be. is not strictly for VR also - though I imagine any system that works for things like Oculus Rift would also work for systems like TrackIR (not even sure if it is supported yet).

I’ve also seen the Oculus Rift section of the wiki page, but the explanation and tutorial is really brief unfortunately.

Any suggestions? Any help is very appreciated!

Thanks very much.

EDIT: Also, do you start off with a certain prebuilt template, and would you suggest first or third person (I’d imagine third since I’d like to see the entire character body, not just shoulder and arms).

For head movement, currently the Rift doesn’t do anything. Right now it just tracks head rotation, but if you offset the headset from the head bone then it can give a similar feel to how you might move your head forward as you rotate it.
The next Rift dev kit will have actual position tracking.

Ah, I see. Is there no way to just bypass the Rift and instead use the mouse to rotate the head? I’d just really like to know how to do since it’s getting more popular in games recently.

I acknowledge at point we’re kinda leaving the VR world, but since I’m still waiting on the new devkit, I guess it’s good to learn different things while I wait.

I suspect that Epic will have implemented by the time we get our hands on the DK2, or shortly thereafter. Then it should work out of the box in UE4, just like rotation does on the DK1 currently.

The code supplied on the Oculus Rift Separate View page is is based on what Ground Branch uses for the Oculus Rift, Freeaim and Freelook.

It doesn’t matter if you use a camera attached to the player model or not, as the actual view rotation comes from by the player controller.

With a few changes, it can support anything you like - Rift, TrackIR, button & mouse based freelook etc.

For freelook, take the DeltaRot and apply it to the players view rotation instead of the controllers rotation.
Something like this:



    // Calculate Delta to be applied on ViewRotation
    FRotator DeltaRot(RotationInput);
 
    FRotator NewControlRotation = GetControlRotation();
    FRotator NewViewRotation = GetViewRotation();
    
    if (PlayerCameraManager)
    {
        if (bFreeLook)
        {
            PlayerCameraManager->ProcessViewRotation(DeltaTime, NewViewRotation, DeltaRot);
            
            // Limit how far we can turn our head before our torso begins to turn too.
            const float YawDif = FRotator::NormalizeAxis(NewAimRotation.Yaw - NewViewRotation.Yaw);
            const float MaxYawDif = 85.0f;
                
            float AddDeltaYaw = 0.0f;
            
            if (YawDif > MaxYawDif)
            {
                AddDeltaYaw = YawDif - MaxYawDif;
            }
            else if (YawDif < -MaxYawDif)
            {
                AddDeltaYaw = YawDif + MaxYawDif;
            }

            NewAimRotation.Yaw -= AddDeltaYaw;
            NewViewRotation.Yaw = FMath::ClampAngle(NewViewRotation.Yaw, NewAimRotation.Yaw - MaxYawDif, NewAimRotation.Yaw + MaxYawDif);
        }
        else
        {
            PlayerCameraManager->ProcessViewRotation(DeltaTime, NewControlRotation, DeltaRot);

            // We've stopped freelooking recently - reset the head angles.
            if (CenterHeadTime > 0.0f)
            {
                float Alpha = (TimeToCenterHead - CenterHeadTime) / TimeToCenterHead;
                CenterHeadTime = FMath::Max(0.0f, CenterHeadTime - DeltaTime);
                NewViewRotation = FMath::Lerp(NewViewRotation, FreeAim, Alpha);
            }
            else
            {
                NewViewRotation = NewControlRotation;
            }
        }
    }
 
    SetControlRotation(NewControlRotation);

    // If our view and aim are different, call SetViewRotation().
    if (NewViewRotation != NewAimRotation)
    {
        SetViewRotation(NewViewRotation);
    }


bFreelook, CenterHeadTime etc are set by a Freelook command, all within the player controller.

Hope it helps.

Thanks for the information, ! I hope you don’t mind if I ask a couple of questions regarding the link you provided (and more).

  1. It lists files such as YourPlayerController.cpp (I realise is probably referring to just PlayerController.cpp) but I can’t seem to find it anywhere - is it in a particular folder? I had to physically go into the project folders to find Build.cs as Visual Studio couldn’t find it which I thought was weird.
  2. Is there a way to toggle mode on and off or to have it has a ‘hold down to activate’? Just asking since that would be better since not has a headtracking device (hopefully buying a TrackIR next month and a OR DK2 a month or so after it is released).
  3. Would you prefer to use a template (for example FPS or Third Person), or just start from scratch?
  4. Finally, I imagine you would (I know I would) prefer to take the C++ route for the link you provided instead of the Blueprints route?

Thanks very much, !

I override everything that affects the player camera, and attach it to a socket on the head (the Rift tries to set its rotation if you don’t override). The, I use the yaw, pitch, and roll of the HMD’s rotation (or an equivalent for AI version of the character) to drive additive blend spaces of the character animating to match its head to the HMD rotation. It will be even more accurate when DK2 ships and blend spaces for translation can be used as well.

Currently, the mouse will control what direction is forward, and then the Rift rotation tracking will be applied on top of that.

Yeah I’ve noticed that if you look down you are not able to move forwards, not a massive fan of that but I guess it makes sense for VR, just not for keyboard/mouse.

Are you experiencing that in the first person template project? There is a known bug with looking down and pressing forward using that template. It is caused by the character trying to move toward the camera’s forward instead of the character’s forward rotation. will be fixed in a future release so that it is not based of off the camera view, but the character’s yaw.

Is the same for all player controllers? It does the same thing for me also if I try to create a ‘first person mode’ with the third person template.

Also, that’s great news!

1. It lists files such as YourPlayerController.cpp.

YourPlayerController.cpp as in the player controller that you are using, what ever you’re calling it.
e.g. ShooterPlayerController.cpp, FirstPersonPlayerController.cpp, GBPlayerController.cpp

2. Is there a way to toggle mode on and off or to have it has a ‘hold down to activate’?

It can be set to toggle (on/off) or be momentary (hold on, release off).
Just depends on how you set everything up.

3. Template or just start from scratch?

The quick VR test project I created to test various bits of code was based on the third person template.
It needed a player model and it isn’t hard to alter the third person movement.

4. Prefer C++ over Blueprint?

I do all the classes in C++ and then use Blueprints to flesh them out.
is a pretty typical practice for UE4 - check out the shooter or strategy examples.

Yeah it happens in 3rd person as well, sorry about that :(. It’s just that when the Template guys made the 1st/3rd person ones, they accidentally set the “get forward vector” to get the Camera’s forward and not the character’s. It was a minor oversight that caused a few headaches.