So I put Cinemachine in long time ago for a follow camera, but what was still nagging at me was there was no way to change the zoom during play… I got into the next section and just couldn’t take it anymore so here’s a script what will let you zoom in and out with the mouse wheel… if we don’t eventually cover a rotate camera, I will make one to post against this lecture in the future…
the script needs to be called ScrollZoom.cs
place this script on the vcam pointed at your player
make sure your vcam is using “Framing Transposer” in the body section.
EDIT- the script now includes reducing your lookahead time when you scroll in close to your player. If the lookahead time is set to zero, no change will happen. If you have a lookahead time you like when you are fully zoomed out, the script will now reduce that lookahead time when you zoom in to keep your player in frame better.
NOTE - once you have a lookahead time you like, uncheck “Save During Play” or it will continuously override your favorite lookahead time whenever you exit play mode. This is not necessary if your lookahead time is 0, as no change will take place anyway.
(You can always revert it from your prefab if you forget this step)
Ok, I’ve tried making camera rotation several times, but today, I struck gold…
First… you need to create a gameObject, I called it Gimble. Child the FollowCamera to the new GameObject.
Then, on the Gimble, I created a script GimbleRotator.
public class GimbleRotator : MonoBehaviour
{
[SerializeField] float rotationSpeed=10;
float desiredRotation = 0;
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(1))
{
desiredRotation += 90;
if (desiredRotation > 360) desiredRotation = 0;
}
float currentRotation = transform.eulerAngles.y;
if (currentRotation < 0) currentRotation += 360; //normalize direction.
currentRotation = Mathf.Lerp(currentRotation, desiredRotation, rotationSpeed * Time.deltaTime);
transform.eulerAngles=new Vector3(0,currentRotation, 0);
}
}
The gimble doesn’t need to follow the player or anything. Most of my attempts have involved childing the follow camera to the player… which with Cinemachine is a disaster.
It’s currently a bit wierd when you rotate from 270 to 360… it’s going to go the long way round. This is fixable, I just haven’t yet. Ideally, say in a mobile game, you’d put two little rotation arrows one on each side of the screen to go -90 or 90.
I am trying to do things with Cinemachine but I can’t get the namespace to work inside VS code.
I keep getting the error that the type of namespace “Cinemachine” could not be found.
I look over the internet for fixes but nothing seems to work for me.
You’re not alone. I’ve seen lots of folks have issues with added packages in VS Code lately.
A few things to check:
The first and obvious one is to make sure your Cinemachine package is installed in the Package Manager. While you’re in the Package Manager, make sure that your Visual Studio Code plugin is up to date. There was recently an update to both the VS Code and VS Community package.
Once this is done, in Unity, (With Visual Studio Code closed) open the Preferences dialogue. You’ll see a list of check boxes followed by Regenerate Project Files.
Check any one of those boxes, and then click Regenerate Project Files.
You can then uncheck that box and click Regenerate Project Files again.
Thanks for the info. I’ve tried that and it still wouldn’t work.
I’ve searched all over the internet and saw that many people had this issue and for others the solution you posted worked, but for me it didn’t.
What finally worked for me was clearing my unity project cache.
Going to Edit => Preferences => GI Cache Tab and clicking the clear cache button.
The joys of the evolving nature of software. A few months ago, my answer would have been to follow the instructions in the Not Making Intellisense lecture, it would have quite probably worked, but things have changed so much that it isn’t sufficient anymore.
I’ve made a note of this to add to future answers.
I’m glad you got it working!
P.S.
As you can see I take control only Horizontal and Vertical locked to 40 degree all time.
Thats because I want it to be as in Divinity Original Sin 2.
To make camera “tactical mode”, I just set angle to 90 for Top-Down look.