New Input System does not work with rotate functions?
private void OnEnable()
{
_controls.Gameplay.Look.performed += Look_performed;
}
public void Look_performed(InputAction.CallbackContext lookVector)
{
lookAim = lookVector.ReadValue<Vector2>();
lookAim *= lookSensitivity;
xRotation -= lookAim.y;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * lookAim);
}
Two Questions in one: 1) I am trying to adapt the new input system to an FPS controller using the code above. If I use the old input system with Input.Getaxis~ it worked fine but this no longer seems to work - instead the two rotation functions seem to be in conflict and only the up/down rotation is working. The swivel seems to be stuck, appears to rotate just a tad bit but keeps getting forced back to previous rotation around x-axis. Any ideas?
2) Do we even need the _controls.Gameplay.Look.performed += Look_performed; lines of code? it seems like the PlayerInputs component makes this seem useless but is somehow in a bunch of tutorials - except they are all outdated and there is no real up-to-date tutorials with the new system that work correctly.
Any help or response would be appreciated. Thanks!
Answer by unity_2Vi4I6AinGsBeQ · Oct 29, 2020 at 03:21 PM
I've also run into this issue. I've noticed the choppiness and the issue where the first mouse delta is super high and pegs either of the clamped boundaries. I've worked around this by throwing out the first several mouse delta events (returning early based on a simple count), but this seems really inelegant to me.
I'm starting to think these issues have to do with handling transforms within the event handler for the Look action, but I haven't figured out a good way to move the processing to the Update method. I've tried storing the rotations in fields that are then applied in Update, but the result is even more jittery and erratic than performing the rotations in the event handlers.
Has anyone else run into this when implementing an FPS controller using the new input system, specifically when using C# events?