Hello,
So I am trying to get my player to enter/exit a vehicle, and the goal is to make a fairly realistic first person look, so instead of creating new cameras and slapping them on sockets of the car, I thought the easiest way would be to play the enter animation, attach the character to the driver seat socket, and then just control the vehicle. Unfortunately this does not keep the same camera. How would I go about keeping the player camera as I posses the new pawn?
This is what I have done:
SetOwner(object);
AttachToComponent(Cast<AControllableObject>(object)->Mesh, FAttachmentTransformRules::SnapToTargetNotIncludingScale, "Sit_Position");
Controller->Possess(object);
EDIT*
After working with it for a while, i came up with this. Ref->GetName() prints fine, but when i set view target, i get an error thrown at that line. Not sure what the issue is, but any help would be appreciated.
SetOwner(object);
AttachToComponent(Cast<AControllableObject>(object)->Mesh, FAttachmentTransformRules::SnapToTargetNotIncludingScale, "Sit_Position");
AActor* ref = Cast<APlayerController>(Controller)->GetViewTarget();
Controller->Possess(object);
FViewTargetTransitionParams params;
print(ref->GetName());
Cast<APlayerController>(Controller)->SetViewTarget(ref, params);
EDIT**
So after some continued digging, I noticed this in the playercontroller.cpp file at the end of the Possess Method:
if (bAutoManageActiveCameraTarget)
{
AutoManageActiveCameraTarget(GetPawn());
ResetCameraMode();
}
This actually confirms what was mentioned below, setting bAutoManageActiveCaeraTarget to false, should prevent the camera from switching. After a little research I found a few others that have had similar issues, but unfortunately no answers. Possibly an issues with how the camera was set in the first place? I just set the player to default pawn, and the controller as the default controller and left it alone. Anyone got a solution?
EDIT***
So I created a player controller class, and tried working with it in there like so:
GamePlayerController.cpp
Possess(object);
SetViewTarget(playerChar);
Where playerChar is a reference to the original character. The issue with this is that I am unable to use the Pitch/Yaw functions for the camera. The input is set up in the player controller class, so it should work for whatever camera is currently being used if I am not mistaken. I have been stuck on this for a while, I would appreciate any input.
EDIT ****
So I think it has something to do with the SetPawnControlRotation bit. Possibly, this is just a guess though.