Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do i change the camera FOV using C++?

I'm trying to implement the fov animation when going into Aim Down Sight. I looked into the Shooter Game example and i created a MyPlayerCameraManager and a MyPlayerController setting the MyPlayerCameraManager as the class. I overriden the UpdateCamera method and used the following code:

 void AMyPlayerCameraManager::UpdateCamera(float DeltaTime)
     class AMyCharacter * Character = PCOwner ? Cast<AMyCharacter>(PCOwner->GetPawn()) : NULL;
     if (Character != NULL)
         bool IsAiming = Character->IsAiming();
         const float TargetFOV = IsAiming ? 60.0f : 90.0f;
         DefaultFOV = FMath::FInterpTo(DefaultFOV, TargetFOV, DeltaTime, 20.0f);
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FString::Printf(TEXT("%f"), DefaultFOV));

The values that are printed on the screen are fine, so the interpolation is working, but the FOV doesn't change at all, so i guess this isn't the variable i should be editing, but this is what they use on the Shooter Game, so what am i doing wrong?

Product Version: Not Selected
more ▼

asked Jun 26 '14 at 02:09 PM in C++ Programming

avatar image

6k 162 129 305

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

Check if you set you PlayerCameraManager class property in your PlayerController class or else it gonna use default one

If you did that and still don' work try doing Super::UpdateCamera(DeltaTime); before your code as parent code may overwrite your code doings (in general you should do Super before if you want to overwrite what parent class does :p) or some other function doing that. go study source code of that class:


Also you don't need to override PlayerCameraManager to change FOV, you can simply send call to camera manager and you can do it in character or playercontroller tick:

more ▼

answered Jun 26 '14 at 02:32 PM

avatar image

37.2k 936 172 1116

avatar image xlar8or Jun 26 '14 at 03:22 PM

Thnks for the response. Yes it's running my custom PlayerCameraManager, it just doesn't change anything. I've tried calling super first, but it's the same result. Yes i knew about SetFOV and it works but I was trying to use the same way as the Shooter Game, because it works fine, so i was just curious in finding out what i'm missing.

avatar image Shadowriver Jun 26 '14 at 08:34 PM

Study source code, mayb you need to override something :) or look on Shooter demo code

avatar image xlar8or Jun 26 '14 at 09:03 PM

I searched and didn't find it, that's why i'm asking here :P

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

You need to apply your PlayerController in GameMode constructor under GameMode.cpp.

Ex: ADemoGameMode::ADemoGameMode(const FObjectInitializer& ObjectInitializer:Super(ObjectInitializer) { PlayerControllerClass = ADemoPlayerController::StaticClass(); }

more ▼

answered Sep 13 '16 at 10:03 AM

avatar image

3 1 3 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

This happened to me too, ¿Are you using a Camera Component on your character? Because if you take a look at the ShooterCharacter code, there is no camera, so there is no need for the SetFOV() on the CameraManager. I ran some tests, just to confirm, and DefaultFOV works without a camera attached to my main character, while SetFOV worked when I the camera component is added to my character.

I hope you find this useful.

more ▼

answered Jul 08 '17 at 09:27 PM

avatar image

130 8 9 11

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question