How do I make the player's camera switch to another camera temporarily?

Hello! I’m trying to implement an NPC dialogue system - so when the player presses E when next to an NPC, they start talking to the NPC. I have the dialogue part working but I’d like to make it so the player’s camera switches to a camera in front of the NPC (so basically the player’s perspective is switched so that they are focused on the NPC).

I have already set up a camera within the NPC blueprint as I’m guessing this is the first step for this sort of mechanic, but other than that I have no clue what to do next. Does anyone have any ideas?

Screenshot 2023-12-06 114936
(This is the camera angle I am aiming for).


(The player would basically be forced to look at the NPC from around this angle, and would not be able to look at them from any other angle).

You could try:

Plug in the reference to the NPC as the New View Target. In the NPC, you could position the cam as needed:

Perhaps set it to orthographic, it seems like that’s what you’re after. To switch back:

image

You can adjust Blend Time to get an animation and play around with curves, too.

Do note that you still have control over the character since they’re possessed. It may help if you disable movement while the conversation is taking place. Otherwise the player may simply wander off and walk into lava, or worse.

3 Likes

This was really clear, thank you so much!!

For some reason though - when I speak to the NPC, the camera switches to focus much lower down on the NPC. I have tried raising the camera within the NPC blueprint, but that didn’t change anything. I also changed the blend time to 10 to see exactly what was going on, and the camera slowly descended to this same position again.

I was thinking I might have set up the NPC reference variable wrong (I’m still a beginner in Unreal Engine and programming in general, so I thought I might have made a mistake such as this).

Screenshot 2023-12-06 124726

Screenshot 2023-12-06 124737

Do you have any ideas as to what the problem maybe? No worries if not - this may very well be a problem with other parts of my project!

1 Like

Could you show the component hierarchy in the NPC?

Could you show how the value of the variable is set?

so when the player presses E when next to an NPC

And this part of the script?

Screenshot 2023-12-06 130428

I hope this is what you meant!

To make the variable, I just made a new variable and from the dropdown list I selected “NPC Example” as an object reference. Again, I hope this is what you meant.

I wasn’t sure what screenshot I should post exactly here, so I hope at least one of these images are relevant:


This is in the First Person Character blueprint, showing what happens when you press E


This is the start of the main dialogue code


This is the end of the main dialogue code.

The dialogue code is quite long and the middle section of it only really involves asking the player questions with the NPC’s response changing depending on their answers. The only camera related code is at the beginning and end.

1 Like
  • the components are fine
  • the variable will not work, it’s null - we do not know which NPC it needs to point at but it might be redundant here, see below:

Isn’t this the NPC we’re going to talk to?

If so, I’d plug that into the Set View Target node. Or you could even handle the camera switch inside the NPC. I assume that when you send this message, in the NPC you get:

So the NPC could switch to its own point of view.


Or this is not how any of this works? When you said:

so when the player presses E when next to an NPC

I assumed the next to refers to:

Is this how you find which NPC to talk to? Am I getting close?

1 Like

Hi there! Sorry for the late reply - your suggestion works really well!! I put the Set View Target with Blend node directly inside the NPC blueprint like you have shown here:

It works perfectly!

You were also right with this part as well:

Thank you so much for your effort, this was a great help!!! =)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.