How to make a camera follow an AI character?

I am new to Unreal Engine.
So, I watched the Unreal Engine’s Getting Started with AI Live Training and I did everything until where an instance of a 3rd person character starts moving to random locations on a nav mesh.
As I want my own player to be controlled by the AI, I didn’t duplicate my player.
From my character instances Details section I disabled the Auto Possess Player tab, And changed AI Controller Class with the one that I created.
However when I play, the game creates another instance of the same character and make it playable. While the other one starts moving around.
So I want the camera to be attached on the AI Character like the 3rd person template. With a rotation control. So that when AI is moving around we can rotate the camera around as we wish.

I would appreciate any answer…
Thanks a lot!

What you want to do is change view target. You might be little bit confused that possession has something to do with it but in reality possession and setting camera (setting view target) are two separate processes, by default when you possess the actor engine automatically sets view target to possessed actor, you can disable that behavior in player controller, by disabling “Auto Manage Active Camera Target” property

I explained view target many times so i just link you:

So now I created a new game mode, I deleted my old third person game mode. I created a new actor blueprint and just added a Spring Arm and a camera in it. I changed the auto possess player settings of my character to disabled and I added my custom AI Controller Class so that it does it’s AI stuff (walking around). I added an instance of my camera actor and changed it’s auto possess player to Player 0. So now when I run the game I can rotate it on the centre.
When I tried to make this camera actor a child of my character it won’t work.

Am I doing something totally nonsense? I still don’t know what to do. Please help.

“camera actor a child of my character” hmmm? what are you trying to do :stuck_out_tongue: Just disable “Auto Manage Active Camera Target” in Player Controller and change view target to camera , if you want to change camera component inside the actor in blueprints you need to disable one camera compoennt and enable other camera component.

But if you want to change view to different actor just change view target, it a player controller function so get player controler and and do “set view target”

Hi all! My query is somewhat similar to what’s discussed here, but taking it a bit further.
So I’m exploring this mechanic of seeing your character through another character’s eyes, while they follow you via AiMove to player controller.

I’ve managed to set the camera to the one in the ai-controlled character, and it works fine, but what i’d really love is to be able to also look around through their eyes via mouse or right analog stick.

I can’t get it to work, i’m stuck. Someone smarter than me please help or tell me why it’s impossible so i can sleep at night

Thank you so much

I had similar setup, here is what i did:

  • all player characters (squad game, wanted flexible system) were AI characters, with really simple AI: just go to location.
  • I moved those characters by finding walkable spots in some small radius like 200 units or so. (Then navigation volume and line trace to find walls etc).
  • then i added camera pawn (just camera, with camera logic like zoom, pan, pitch). Camera Pawn would read world location of controlled player character and snap to it (updating location and rotation on event tick)
  • some tweaks to camera pawn were required: using camera arm with small lag to soften and hide jittering (was minimal anyway, but just in case somebody could notice it)

I tried to swap AI controller for player controller when needed, but i think it was impossible or bugged during runtime, or maybe multiplayer was not working well with it. Also for tactical top down squad game (and for debugging) being able to detach camera was great.

So you can make something like that, just more advanced (3rd person and FPS like modes for camera). Add sockets around player character and snap to them, set camera arm length to 0 for FPS.

1 Like

thanks for answering. Problem is, my camera POV is supposed to be 1st person, but I still want to fully control the character that you see in front of you. Eventually I settled to this:

  • i put a camera on the AI character, snapped to a socket i attached to the head bone (makes for some nice camera shake too)
  • in the player character i use axis events to control local/relative rotation of that camera object inside the AI controlled character

It’s not perfect, i don’t exactly know why the rotations sometimes compound and i get a weird roll in the camera, even though I don’t mess with roll rotation at any point.

Another problem is if i rotate too far i see the inside of the head…

Thing is, ai movement on the pawn influences the capsule, which in turn drives the anims/body of the character. I i’m thinking maybe I can set the rotation of the head bone, or would that be overly contorted and complicated?

I’m not doing multiplayer, so even if the ai char is doing an exorcist style 360 turn, no-one could see it.

Split skeletal mesh into parts you want to see (even in first person) and parts that you do not want to see (like head from inside).

Then set VISIBILITY to hidden for those meshes that you want to be hidden.
However reflections will not render them.

Or move camera forward a bit to not have clipping with head.

You can also add virtual socket to skeletal mesh, make it child of root or pelvis or whatever has movement you want to follow (for eg, head can turn and you do not want this, pelvis will add some movement from walk animation) So you can make virtual socked baed on root, then move it up to be at eyes level and a bit ahead of it.