Implementing a True First Person camera

Hello !
I wrote a new blog post which this time cover how to properly setup a True First person camera.

Something which looks like that :

I had to implement it for my current project which made me want to share my method. Mostly because I met a few issues and the solutions weren’t really obvious. I’m hoping this will help other people looking into the same subject as during my time I wasn’t able to find a lot of documentation. :slight_smile:

The tutorial is available on my blog : http://www…fr/blog/2018-06-tr…nreal-engine-4

Where can I download this??

There are no download, the tutorial only provide an explanation of my setup/system.

this is awesome fro :slight_smile: thanks for the tutorial

I really enjoyed reading the tutorial. I’ve set up a similar system for our project and it’s interesting to see how other people solve these kind of things. Thanks!

Very intersting, thank you!

Always happy to see people sharing and I’m even happier to see other peoples approaches on creating a TFP viewpoint!

That said, I have a few points and some suggestions if you will bear with me.

1 Frame Lag

If you’re experiencing a 1-frame delay in the rotation, I am not sure how it is caused by the tick order you mentioned.
You see, pawn controlled by the player controller already has its rotation updated by APlayerController::UpdateRotation() before its ticks.

void APlayerController::UpdateRotation( float DeltaTime )
    // Calculate Delta to be applied on ViewRotation
    FRotator DeltaRot(RotationInput);
    APawn* const P = GetPawnOrSpectator();
    if (P)
        P->FaceRotation(ViewRotation, DeltaTime);

This is done by before APlayerController::Tick() is even called:

    └─ APlayerController::PlayerTick()
        └─ APlayerController::TickPlayerInput()
        └─ APlayerController::UpdateRotation()
            └─ APawn::FaceRotation()
    └─ APlayerController::Tick()

Thus your call to PreUpdateCamera() at the end of APlayerController::Tick() is redundant.
It may simply be something unique to your setup.
For instance, if you have bUseControllerRotationYaw set to false on your character, FaceRotation() won’t do anything.

Aim Offset

You can get the local rotation for use in the animation blueprint more easily by using the method provided by the ShooterExample project:

FRotator AShooterCharacter::GetAimOffsets() const
    const FVector AimDirWS = GetBaseAimRotation().Vector();
    const FVector AimDirLS = ActorToWorld().InverseTransformVectorNoScale(AimDirWS);
    const FRotator AimRotLS = AimDirLS.Rotation();

    return AimRotLS;

Or even something like:

    (GetBaseAimRotation() - GetActorRotation()).GetNormalized();

Playing montages

I recommend using an animation curve fed into the alpha value of your aim offset node instead.
In this way you can easily blend the aim offset in/out depending on the montage without relying on a hard coded fix.

Animation tip to avoid motion sickness

Great advice, though another method to reduce the issue is to use the controller rotation at all times.
This will mean using a different approach when you want the animation to affect the rotation of the camera, but otherwise works quite nicely.

Thanks again for sharing! :slight_smile:

Thanks for the feedback Kris ! :slight_smile:

FaceRotation is not the same as the Tick function however. Since FaceRotation is used to update the mesh/character rotation. The Character class will still tick too late in my case, but I guess I could have called my camera update function from there. I also could have used the rotation booleans in the Character class, I have been hacking the game code for so long that I probably inherited some old game code (because they didn’t exist at one point as far I remember).

Hmm, I didn’t know about this function. Looks nice indeed !

Ho, good point. I was planning into using anim cuves for enabling/disabling IK. That would make sense to use it for the Aim as well.

That’s something I have looked into at some point when I had issues with the frame lag. However that’s a bit annoying to handle if you don’t have a perfect 180° angle rotation. For exemple the head animation in my case can look at 170/160° up max and further than 0° bottom. Handling that without flipping and Euler rotations issues might be difficult. Here the rotation is used as a simple scale in the end.

Please, blueprint version add(

Wow this is very cool. I’m assuming it would be easy to build in a toggleable option so players who wanted a more traditional FPS camera could have it? I know headbob really bothers some players.

Headbobing can be mitigated by applying a constraint on the head rotation/location. Similar to how Star Citizen managed it.
In another place someone summarized it up as this :

having a traditional FPS camera on top as a toggle would void one of the main advantages of this system: the fact that you don’t have to build 2 different animation sets+systems.
for a true first person to work (specially if guns are involved) you’re going to want the animations to be stabilized to a certain degree as well. if you rely only in a code-based solution you can easily end up with a stable camera that sits on top of an unstable character which would lead to viewing “wrong” parts of the character very frequently (inside of the neck or arms, etc), and having the arms not properly positioned on-screen and jerking all around.

for my last game (UE3-based) I implemented my own code-based stabilization for the true first person camera, as well as fine-tuning all third-person animations to work in true first person. it worked well enough for an indie game just as it would work for an adventure or parkour game, but it’s not quite there from what you’d expect from a AAA shooter

Yep, I second what @Chosker mentioned.
In my case I prefer to refine the animations first. Still I may implement some movement cancellation in code later if people feel sick when playing my project. :slight_smile:

I have a question. What does function “GetPlayerCameraInput()” returns and what is its definition. Try to look up the definition in the source engine but not found so I guess it’s must be your own code.
Thanks :smiley:

Man, absolutely awesome tutorial! Exactly what i need for!!

But i am struggling trying to achieve the basic FP walk behavior… i hope you can have the time and patience to share more info about your Player Controller and Character classes…

  • The general setup (script) is: create a custo playercontroller class, create a custo Character class, assign the custom PlayerController + Character classes in a custom GameMode?
  • In the PlayerController class, i am clueless about the code used in the GetPlayerCameraInput() and IsCameraInputEnabled() functions, and to create/populate the ViewYawSpeed/ViewPitchSpeed variables.
  • In the Character class, i have doubt about the FirstPersonCameraComponent creation (did you create and positioned the Camera component in the script?). Can you share more info? I am creating the camera in a blueprint derived from the custom Character class, but then i can´t access it from code.
  • In the Character class, how did you create a local variable (CameraLocalRotation) that can be acessed by the animation blueprint?

I can´t thank you enough!

Yes, that’s the general way to do it and I do it like this as well.

Lot’s of people are confused by this part in my code : it’s actually custom functions but nothing very special. So I did an addendum to my blog-post about those, take a look again ! :slight_smile:

The Camera component is created in the constructor of my Character and then attached to the head bone of my Character Skeletal Mesh Component. I use the native class, not a custom one. In you case you may want to look into how to spawn/create component based on a blueprint class. Such as : Spawn Blueprint from C++ - Editor Scripting - Epic Developer Community Forums

I have a function in my Character class that can be accessed via Blueprint. In the Event Graph of my AnimBlueprint I use the “Event Blueprint Initialize Animation” node to get the Pawn Owner and the cast it to my Character class. This way I get a reference to my Character and can query the Camera variable.

This is awesome. Can you share header and cpp file please.

+1, @, can you share the full source code of your Controller and Character? It would be easier to understand what’s missed out.

I can’t really share my source files, while I don’t really have anything to protect they are too much nested with other functionalities and classes. Cleaning that would require too much time. Again, if you are confused by some of the functions called by my code mentioned in the blog-post note that I edited it to add some clarifications.

The guide looks great. Could I ask you some questions about the specifics of making this. I’m at a loss about how to begin.