limit first person camera's pitch rotation c++ ue4

Viewed 1664

So, I'm trying to limit how much the camera can look up and down in my first person game and I wasn't able to get a good result so far. I made a very basic method for looking up and down (I'm still a noob in c++). What should I add to my code ?

void AYT_Character::LookUpAtRate(float value)
{
   AddControllerPitchInput(value * BaseLookUpAtRate* GetWorld()->GetDeltaSeconds());
}

any help will be appreciated, I want to do this in c++ and avoid blueprints as much as possible for now.

1 Answers

From a Character class you can set it in BeginPlay() not the constructor:

APlayerController* PlayerController = Cast<APlayerController>(Controller);
if (PlayerController)
{
    if (PlayerController->PlayerCameraManager)
    {
        PlayerController->PlayerCameraManager->ViewPitchMin = 45.0; // Use whatever values you want
        PlayerController->PlayerCameraManager->ViewPitchMax = 100.0;
    }
}

I removed CastToPlayerController answer since it is becoming deprecated.

Related