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

So i have this playable character the I controll, but i want the camera to follow a npc instead of the playable caracter, how can i do that?

Basiclly like a sports court side camera that follows the enemy player who has the ball for example

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

I cant find that ViewTarget anywhere, can you send me a screen shot pls?

Im gonna try be more specific:

I have this character that is a NPC:

And the i have this camera that I want it to be always on this side of the square (arena) like a typical camera in a football or basketball game:

What i want is to this camera to follow that NPC character without rotation, and i want this camera to be the main and starting camera.

Hope I was clear. If you could help i would be really greatfull

For the NPC you’re talking about, set up a camera component on a spring arm in that NPC Pawn, similar to how it’s done in the 3rd person player.
Mark the rotation as being in world space, not object space. Set it to whatever rotation you want.
When your playercontroller begins playing, call SetViewTargetWithBlend on the given NPC.

1 Like

“call SetViewTargetWithBlend on the given NPC” this is given by the get player controller node? if yes how do i define/check the NPC index?

i also dont understand how do you get that camera reference since you tell me to put a camera as a component of the npc pawn

Nevermind i figured out. Thank you for the help :slight_smile: