Cinemachine: Keeping camera orientation when switching between freelook cameras

Hello, I’m making a tactical game with a number of player-controlled agents. I want to be able to click on an agent and have the camera follow and look at that agent, but be able to orbit that agent. I’ve currently set each agent with their own freelook camera, and have a script that enables the selected agent’s camera and disables the others. So far so good. What I’m struggling with is that each camera remembers its last position, so that when I switch, I often end up with the main camera facing a very different direction to that in which the player was last looking.

What I want:

Agent A is selected, Camera is south of A facing world north.
Player selects agent B (who is north of A)
Camera moves to just south of agent B and still faces world north.
Player rotates camera to face south, and see agent A.
Player selects agent A
Camera moves to just north of agent A and still faces world south.

What I’m getting

Agent A is selected, Camera is south of A facing world north.
Player selects agent B (who is north of A)
Camera moves to just south of agent B and still faces world north.
Player rotates camera to face south, and see agent A.
Player selects agent A
Camera moves to just south of agent A and faces world north.

Is there a way to keep the camera facing the same way in world when I switch between the freelook cameras, or would I be better to have one free look camera and change its follow and lookat properties?

Probably the easiest approach would be to use a single FreeLook targeting an invisible gameobject, and put a custom script on the gameobject to lock position with the currently selected player.

Thanks very much I’ll give that a try.

@Gregoryl I have the same question but in my case the camera switches from player character to different vehicles that have different freelook camera requirements.

A single freelook wouldn’t work for this so any other suggestions please?

Use multiple FreeLooks, one for each target, and activate/deactivate as necessary. CM Brain will blend. You can use InheritPosition on the FreeLooks.

6964949--820601--upload_2021-3-23_10-17-6.png

Thanks a lot, that worked a treat!

1 Like