How do I change variables in the cinema chine free look script in c#?
Like change the MiddleRig ScreenX and similar settings?
I
How do I change variables in the cinema chine free look script in c#?
Like change the MiddleRig ScreenX and similar settings?
I
if figured most of it out, although I can’t figure out how to loop through the rigs. My guess is that rig 0,1 and 2 correspond to the top middle, and bottom rigs in a 3 rig system. Can I somehow get the rig length and loop through these instead of explicitly putting 0,1,2?
btw the float f should go from 0 to 1 with .5 being the middle, and I used .1 to ,9 to keep the character in screen.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
public class CinemachineManager : MonoBehaviour
{
public CinemachineFreeLook cinemachineFreeLook;
public void SetCameraOffset(float f)
{
cinemachineFreeLook.GetRig(0).GetCinemachineComponent<CinemachineComposer>().m_ScreenX = f;
cinemachineFreeLook.GetRig(1).GetCinemachineComponent<CinemachineComposer>().m_ScreenX = f;
cinemachineFreeLook.GetRig(2).GetCinemachineComponent<CinemachineComposer>().m_ScreenX = f;
}
public void SetCameraOffsetY(float f)
{
cinemachineFreeLook.GetRig(0).GetCinemachineComponent<CinemachineComposer>().m_ScreenY = f;
cinemachineFreeLook.GetRig(1).GetCinemachineComponent<CinemachineComposer>().m_ScreenY = f;
cinemachineFreeLook.GetRig(2).GetCinemachineComponent<CinemachineComposer>().m_ScreenY = f;
}
}
Glad you figured it out. I was going to direct you to the Scripting scene in the CinemachineExamples.
You can write a loop for the rigs. Rig length is always 3.
That’s just what I wanted to know about the number of rigs:) thanks you I’ll make a loop.
I’m so glad I have a new project and am finally able to use cinemachine for my project. It makes an amazing camera system for the player and adds a lot of beauty to it.
is there any way to smoothly set these values instead of them snapping into place
You would have to make a coroutine and gradually lerp them. However, if you find yourself needing to do this, then it’s possible that the FreeLook is not the right camera type for your purposes. Can you describe the context, and what you would like the camera to do?
i wanted to just lower the camera while the player is crouched. i couldn’t get that to work so i tried using 2 different free look cameras within a state driven camera that activated during certain animations but they don’t follow each other. that made it so that if you were standing and looked left, and then crouched, the crouch camera will be where you left it last, not where the standing camera is. kind of a specific problem but any insight would be greatly appreciated thank you!
If you check this option on the FreeLooks then they will follow each other:

However, I am wondering why you are using the FreeLook if you are targeting groups. Normally, a FreeLook is used to look at and follow a player. If you target the player’s head, then the camera will automatically lower when the player does. Why are you involving TargetGroups? Or perhaps I am misunderstanding you because of the rest of this thread.
i used a target group because i tried using the head/spine bones but the camera would follow the bones every movement during the animations which made the camera kind of move around violently and unnaturally, at least in my case, and it was an effect i wasn’t trying to get so i had to just have the camera look at and follow the whole player group and it seemed to be smoother. but checking those “inherit position” boxes actually solved my issue i really appreciate it!
@Gregoryl I would like to rotate the freelook camera via script and the new input system.
This is my current state:
void LateUpdate()
{
if (inputActions.SpectatorLook.sqrMagnitude >= LookThreshold)
{
CM_FreeLook_TopRig.GetCinemachineComponent<CinemachineComposer>().m_ScreenX = inputActionsHandler.SpectatorLook.x * Time.deltaTime * RotationSpeed;
CM_FreeLook_MiddleRig.GetCinemachineComponent<CinemachineComposer>().m_ScreenX = inputActionsHandler.SpectatorLook.x * Time.deltaTime * RotationSpeed;
CM_FreeLook_BottomRig.GetCinemachineComponent<CinemachineComposer>().m_ScreenX = inputActionsHandler.SpectatorLook.x * Time.deltaTime * RotationSpeed;
CM_FreeLook_TopRig.GetCinemachineComponent<CinemachineComposer>().m_ScreenY = inputActionsHandler.SpectatorLook.y * Time.deltaTime * RotationSpeed;
CM_FreeLook_MiddleRig.GetCinemachineComponent<CinemachineComposer>().m_ScreenY = inputActionsHandler.SpectatorLook.y * Time.deltaTime * RotationSpeed;
CM_FreeLook_BottomRig.GetCinemachineComponent<CinemachineComposer>().m_ScreenY = inputActionsHandler.SpectatorLook.y * Time.deltaTime * RotationSpeed;
}
}
It doesn’t work correctly. How shall that be done correctly?
I don’t understand why you’re trying to do that. Why not just connect the input directly to the FreeLook using CinemachineInputProvider?
Because it doesn’t work in my case.
I put my input actions there responsible for look and zoom and it just doesn’t work and I don’t have time to find out why it doesn’t work.
I also want to have full control over it in script with things like giving authority to the players and so on (I work on multiplayer game).
You can drive the FreeLook axis values manually from script by writing to freeLook.m_XAxis.m_InputAxisValue and FreeLook.m_YAxis.m_InputAxisValue.
Alternatively, you can write a script that implements AxisState.IInputAxisProvider, add it to the FreeLook, and provide your input values whenever freeLook asks for them.
Alternatively, you can just use CinemachineInputProvider the way it was intended. It might be a good investment to figure out what you’ve done incorrectly to make it nonfunctional. The way to manage different players would be to manage it at the input level, not at the FreeLook level.
Thanks for the response, Greg.
Here is my updated code:
void LateUpdate()
{
if (inputActionsHandler.SpectatorLook.sqrMagnitude >= LookThreshold)
{
Debug.Log("X :" + inputActionsHandler.SpectatorLook.x * Time.deltaTime * RotationSpeed);
Debug.Log("Y :" + inputActionsHandler.SpectatorLook.y * Time.deltaTime * RotationSpeed);
CM_FreeLookCamera.m_XAxis.m_InputAxisValue = inputActionsHandler.SpectatorLook.x * Time.deltaTime * RotationSpeed;
CM_FreeLookCamera.m_YAxis.m_InputAxisValue = inputActionsHandler.SpectatorLook.y * Time.deltaTime * RotationSpeed;
}
}
Unfortunately, it doesn’t work. I checked in Debug.Log if it’s printing values and it does:

FreeLook camera just look at target and doesn’t respond to mouse movement.
CinemachineInputProvider.
I have been trying to make it work for a few days now. Nothing works here.
It doesn’t print any error.
Also, there is some parameter Player Index and what shall I do with it? The documentation doesn’t say where shall I take it from when I develop a multiplayer game.

What version of Cinemachine and Input are you using?
Can you show the inspector for the FreeLook?
When you drag the FreeLook’s axis values in the inspector, does the camera do anything?

Unity version 2020.3.11f1.
Cinemachine version 2.6.5.
Input System version 1.0.2.
“When you drag the FreeLook’s axis values in the inspector, does the camera do anything?”
Yes, it rotates.
Looks like you have a script to push values to the FreeLook, and you also have an input provider from which the FreeLook pulls input. If the InputProvider (for whatever reason - to be determined) is always providing 0, it will overwrite the values you are pushing. If you want to use the pushing script, remove the InputProvider.
I have the code commented that pushes the values through scripts when the Input Provider is attached to the freelook cam.
In LateUpdade too.
//MyInputActions.Spawner.CamLook.performed += ctx => OnCameraSpectatorLook(ctx.ReadValue<Vector2>());
//MyInputActions.Spawner.CamLook.canceled += ctx => OnCameraSpectatorLook(ctx.ReadValue<Vector2>());
Interesting note, when I put to this InputProvider values from other InputAsset that is completely not present in my project like from Starter Assets - Look, then the camera starts moving.
So my guess is that there is something strange in how you have set up your inputs. If you create a new FreeLook camera, there will be a button in the inspector to add an InputProvider. Press it, look at the default inputs it generates, then try to find the differences between that and yours.
Where is this button? I don’t see it. I add it by clicking Add Component → Cinemachine Input Provider.