Camera bug on player death

When I die in the game, my camera seems to “jump” backward from where my player was. I’m not sure how to fix this so it stays in the position it was before death. It seems to be working as expected in Sam’s lecture.
Here’s a video of what I am referring to.

Here is my EndGame() function:

for (AController* Controller : TActorRange<AController>(GetWorld()))
{
	bool bIsWinner = Controller->IsPlayerController() == bIsPlayerWinner;
	
	Controller->GameHasEnded(Controller->GetPawn(), bIsWinner);
}

That would be because you are detaching the controller from the pawn.

Are you referring to the call to DetachFromControllerPendingDestroy() in ShooterCharacter.cpp?

I just commented it out and it is having the effect you’re describing. To my recollection though, Sam leaves that statement in and his camera isn’t zooming out like mine is.

Also, why does that statement move the camera anyway? I thought we just included that line to disable input from the player upon death.

Is there something else I’m missing?

I checked out his project and it does on my end.

Because you’re now no longer possessing the character and I guess there was a change in the engine for what happens when you do.

If I recall correctly it was to prevent the AI continue to control the character when it dies.

1 Like

I just reviewed “Ignoring Actors in Line Traces” and Sam said that the intent of DetachFromControllerPendingDestroy() was to both prevent the AI from being able to shoot upon death and to prevent the player from navigating around the world. So, I think we both described it only partially.

Do you have any suggestions for a good course of action towards preventing this odd camera behavior without commenting out DetachFromControllerPendingDestroy()? I researched it a little bit and found out that setting it up involves the ShooterController's ACameraManager class, which apparently sets the camera in our viewport in the circumstance where the controller can’t access the camera on our pawn. I’m not sure where to go from there, though. Perhaps we can obtain a reference to the pawn camera in our controller script, somehow?

Privacy & Terms