Hi,
I would like to have a toggle for two cameras in runtime
- A 3rd person camera (spring arm and the camera component)
- A debug camera (in front of the character) that will follow an arbitrary AI character (obviously different orientation than the 3rd person camera)
I setup the two cameras (3rd person and Debug) in the PlayerCharacter BP, but when switching to the debug camera, it gets positioned at the center of mass of the AI Character that’s been set as the view target.
After testing I found, when I set up a “third” camera in the AI Character, like the debug camera in the PlayerCharacter BP, it works!
I expect that only the Player Character should set up the two cameras and use the SetActive to turn on/off the ones you need, preserving the arm spring and camera relative locations as defined in the BP.
Is this assumption correct?
Why would I need to set up a “third camera” in the AI Character that’s been used as the new view target for this to work?
if (bThirdPersonCamera)
{
APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(GetCharacter());
PlayerCharacter->GetFollowCamera()->SetActive(true);
PlayerCharacter->GetFrontFollowCamera()->SetActive(false);
SetViewTarget((AActor*)PlayerCharacter, Params);
}
else
{
AActor* NewTarget = nullptr;
APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(GetCharacter());
PlayerCharacter->GetFollowCamera()->SetActive(false);
PlayerCharacter->GetFrontFollowCamera()->SetActive(true);
for (size_t i = 0; i < FoundActors.Num(); i++)
{
AAICharacter* MyChar = Cast<AAICharacter>(FoundActors[i]);
if (MyChar->Type == ETypes::SpecialType)
{
SetViewTarget((AActor*)MyChar, Params);
break;
}
}
}
Thanks