Best way to zoom in on an AI?

Hello!

I have an idea for my game, where I’d like to be able to move the player camera, to a specific transform that the AI has stored, so that when interacting with the AI, the player character zooms in to that location, puts the AI in focus, and then when exiting, it puts the player back in focus.

If there is any better ways of doing this, feel free to comment, but thats what I want to go for.

At the moment I’m using an interface to signal that the player is interacting with the AI, and I have that properly set up. All I would like now is to find a way to smoothly move the camera to focus on the AI.

So far I have tried this:

Make a camera attached to the AI, and save its transform.

On the interface event, get the player camera, get the camera transform from the AI, and set relative transform on the player camera. But when i do it, the player seems to teleport miles away?

I did check with print strings to make sure that the transform is not set to 0

I also have a feeling I’m supposed to use a timeline to smoothly move it to the location and back. but I’m guessing that wont work as desired since I’m having that issue with the player being teleported away.

Any suggestions are welcome!

Quick edit: Using “Get world transform” messed up the location. Using “Get relative transform” works better.

Still wondering though if someone knows of a better way to do this along with the timeline! :slight_smile:

Many ways to switch cameras. Perhaps this is enough:

  • in the player that does the interaction (use the interface as you see fit, we just need an actor reference for the player controller to target):

  • the AI NPCs have cameras, too:

  • the end result:


Setting it up to work with a timeline is very doable but needs much more script, but it also give you much more control.

1 Like

Hi! I tried this, but it seems that the position it snaps to, is behind the AI. Is that because of the camera placement of the AI?

Sorry, spoke to soon! I changed the camera, and it fixed it.

But say I want to later have the AI be posessed, like a normal character. Should I use the same method on posess, to switch the camera behind the character? Or should I be making a new camera? Does it know what camera it should go to?

Yes, while the target is an actor, the first camera to be found there will be used to interpolate the transform - the Set View Target with Blend node is a somewhat simple fire & forget solution.

If no camera is found on the target actor, the end point will equal the transform of the actor.

Is that because of the camera placement of the AI?

Move the AI’s camera and observe the result. Also, make sure to populate the Blend Time and Blend Exp fields.


Do note that the movement you’re are seeing has nothing to do with the Player’s Camera or the AI cam - we are not touching them at all. Those pawns’ cameras serve as start/end points the camera manager is using to produce data to move its own camera. This behaviour can be further overridden by using a manager in the player controller.

2 Likes

Nah, possess as usual. Possessing sets the view target automatically afair.

  • the player has its own camera
  • the NPC has its own camera
  • the camera manager has its own independent camera, it actually does the heavy lifting of storing the necessary transforms during the transition

As a side note: you’ll need a system that prevents interruption of the animation. Try switching the camera before it finishes moving to see what I mean.

2 Likes

I see! Thank you so much for explaining and taking time to help. Didn’t know this tool existed, but it seems very useful!

Have a good day :smiley:

2 Likes