How to put camera following a npc while you controll your player?

Each PlayerController has a ViewTarget. The ViewTarget is (confusingly) not the thing being viewed, but the thing that contains the camera being used.
So, you can do one of four things:

  1. Make the PlayerController contain its own camera component (I think it already does by default,) and set itself as the ViewTarget, and the use some blueprint in Tick that points the camera in the position and direction you want (perhaps using LookAt to find the right rotation.) This is what you typically do for “play board game without even having a Pawn” situations. This is flexible, and is easy to drop into any game setup without disrupting any of the other classes/objects.
  2. Create a new CameraActor, make that the ViewTarget, and move this actor around using some separate mechanism – from PlayerController, Player Pawn, or NPC Pawn tick, or maybe from its own Tick function. This is what you typically do for “view through security camera” type situations. This makes it easy to know where the camera is, and customize its behavior in a single place.
  3. Make the NPC the ViewTarget, and have each follow-able NPC have its own camera setup. When that NPC is the ViewTarget, the player view will be taken from whatever that camera component is doing. You could attach it with a spring arm, with a transform offset, or some other way. This is what you typically do when you can “switch player bodies,” such as when taking control of individual units in an army. It makes it easy to customize how the camera behaves per target pawn kind.
  4. Make the player pawn camera component be more flexible in how it positions itself. Don’t make it sit on a spring arm in local space; make it be world space, and update it in Tick to follow whatever NPC should currently be followed. This is what you’d typically do if you have a camera that’s more like a “periscope” and can be moved around, but still based on the player pawn.

The call to make some object-containing-a-camera be the camera-for-a-player-controller is SetViewTargetWithBlend. You can set the blend time to 0 to make a hard cut, or provide a time when switching to “zoom” the camera between different perspectives. Although, if you switch perspectives, you probably want a specific animation for this, like pulling out/up, then moving to the next place, then zooming in/down, and you’d need more careful control to achieve that than you get by simply setting a blend time.

1 Like