I'm new on Unity Scripting, and I'm trying to make a ThirdPersonCamera, so following this tutorial he can move the mouse up and down, and left and right correctly

The script used was
posY += Input.GetAxis("Mouse X") * mouseSensitivity;
posX -= Input.GetAxis("Mouse Y") * mouseSensitivity;
// mouseSensitivity can be changed
Vector3 targetRotation = new Vector3(posX, posY);
transform.eulerAngles = targetRotation;
Due to the new Input System, using Input.GetAxis("Mouse X") throws an InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings error.
So I tried to use
private PlayerInputMovement inputCamera;
void Awake(){
inputCamera = new PlayerInputMovement();
inputCamera.Player.Camera.performed += context => cameraInput = context.ReadValue<Vector2>();
}
void Update(){
Camera();
}
void Camera(){
posY += cameraInput.x * mouseSensitivity;
posX -= cameraInput.y * mouseSensitivity;
// mouseSensitivity can be changed
Vector3 targetRotation = new Vector3(posX, posY);
transform.eulerAngles = targetRotation;
}
And got this, but if I keep my mouse on an axis, it keeps rotating to that side

So... is this a correct way to replace the old Input.GetAxis("Mouse X") or Input.GetAxis("Mouse Y") to the new Input System? How can I stop it from keeping rotating?
Mouse.current.delta.x.ReadValue()
Mouse.current.delta.y.ReadValue()
You probably tried to import a new input system package for multiple input devices compatibility. These type of errors are due to conflict between old and new input system packages and are probably resolved in latest updates. To resolve this issue, Go to Edit -> Project Settings->Player->Under Other Settings under Configuration is the option Active Input Handling. Select Both. Unity will restart. Now your problem should be solved. You will be able to use old input system packages and the new ones also simultaneously. Cheers. P.S Click here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With