Hello, anyone can explain to me how to make mouse look for first-person and third-person players using the new InputSystem?
Unfortunately, I’m yet to delve deeper and get some practice with it myself, for now I’ve just acquainted myself with the core principles. Have you tried searching for this, because this has to be pretty common? For example
This is my look code for my current first-person project. It’s attached to the player’s root object and “vCam” is the camera transform:
[SerializeField]
PlayerInput pi;
[SerializeField]
bool InvertY = false;
[SerializeField]
float MaxPitch = 89f;
[SerializeField]
float LookSensitivity = 1f;
[SerializeField]
Transform vCam;
InputAction lookAction;
float pitch = 0;
private void Start() {
Cursor.lockState = CursorLockMode.Locked;
lookAction = pi.currentActionMap.FindAction("Look");
}
void Update() {
ProcessLook();
}
private void ProcessLook() {
var lookInput = lookAction.ReadValue<Vector2>();
pitch += lookInput.y * LookSensitivity * (InvertY ? -1 : 1);
pitch = Mathf.Clamp(pitch, -MaxPitch, MaxPitch);
vCam.localRotation = Quaternion.Euler(pitch, 0, 0);
transform.Rotate(0, lookInput.x * LookSensitivity, 0);
}
My “Look” input action is set up as follows:
Here, I made a Google Docs on it
Not sure about it tho I’m just 9
Watch Brackeys’s video on it (Youtube)
That is using old inputsystem.
I’ll try that. Thanks.
Well, that almost works, only thing is that my character is also slowly rotating without moving the mouse.
angle += mouse.delta.y.ReadValue() * Sensitivity * -1;
angle = Mathf.Clamp(angle, -maxAngle, maxAngle);
Camera.main.transform.localRotation = Quaternion.Euler(angle, 0, 0);
transform.Rotate(0, mouse.delta.x.ReadValue() * Sensitivity, 0);