Camera zoom out relative to player scale (using CinemachineFreeLook)
I am using CinemachineFreeLook to create a third person camera experience for my game. My player can scale up and increase its size during the game. How can I make the camera to zoom out so that the player can fit inside the FOV of the camera? At the moment if the player grows too much, I can't see the rest of the map.
Answer by Eriffe · Sep 05, 2020 at 02:51 PM
I managed to work around this problem. The FOV was not what I was looking for. I really wanted to increase the orbit radius so the camera could have a broader vision of the scenario. In order to do that I created a function to zoom the camera when needed:
public void UpdateOrbit(float zoomPercent)
{
for (int i = 0; i < cinemachineFree.m_Orbits.Length; i++)
{
CinemachineFreeLook.Orbit[] originalOrbits = cinemachineFree.m_Orbits;
cinemachineFree.m_Orbits[i].m_Height = originalOrbits[i].m_Height * zoomPercent;
cinemachineFree.m_Orbits[i].m_Radius = originalOrbits[i].m_Radius * zoomPercent;
}
}
You can get the cinemachineFree set by simply using:
using Cinemachine;
cinemachineFree = GetComponentInChildren<CinemachineFreeLook>();
Your answer
Follow this Question
Related Questions
Script has been added to my object but it cannot be found using GetComponent() 1 Answer
Centering camera between my player and a selected object. 0 Answers
Problem with a Camera Follow Script 1 Answer
Needing a hand circumventing a "Missing Reference Exception". Any help sincerely appreciated! 1 Answer
How to make FPS character jump in the direction my camera is facing? 0 Answers