- Home /
Cinemachine input axis camera movement,cinemachine input axis control with script
Hello, I am new to cinemachine and am trying to make a camera movement using cinemachine free look camera where it will follow the player behind but when right-click is pressed the camera will be free to rotate and orbit the player. After right-click is released then it will snap back to its original position behind the player.
I think I need use the variables "Input Axis Name" for the X and Y axis in the Axis Control and have then set when the right-click button is pressed or released. However I am not sure how to get these variables in a script. Any help is appreciated.
Answer by MysticalSkyWhale · Nov 10, 2020 at 01:16 AM
I recognize that this question is probably long dead, but I had a similar question just the other day. I think I've found a solution that the both of us were looking for.
Make sure you put using Cinemachine;
at the very top of your script. Then just copy/paste this in.
void Start()
{
CinemachineCore.GetInputAxis = GetAxisCustom;
}
public float GetAxisCustom(string axisName)
{
if(axisName == "Mouse X")
{
if (Input.GetKey("mouse 1"))
{
return UnityEngine.Input.GetAxis("Mouse X");
}
else
{
return 0;
}
}
else if (axisName == "Mouse Y")
{
if (Input.GetKey("mouse 1"))
{
return UnityEngine.Input.GetAxis("Mouse Y");
} else
{
return 0;
}
}
return UnityEngine.Input.GetAxis(axisName);
}
Your answer
Follow this Question
Related Questions
Jerky 3rd Person Camera Following Movement and Rotation 0 Answers
camera movments fixed.. character controller without using character controller -.-' 2 Answers
Rotate Camera to the object 0 Answers
How to have free rotation camera? 1 Answer
Free Orbit Cam and Mouse Aim Cam aren't working together 0 Answers