I’m making a player controller using new input system. Everything works except clamping.
This is the script
private InputController inputController;
public Transform player; // an object to rotate
Vector2 touchDelta; // vector for inputs
public float sens;
void Update()
{
touchDelta.x += inputController.Player.Look.ReadValue<Vector2>().x;
touchDelta.y += inputController.Player.Look.ReadValue<Vector2>().y;
float xRot = -touchDelta.y * sens;
float yRot = touchDelta.x * sens;
xRot = Mathf.Clamp(xRot, -90f, 90f);
player.localRotation = Quaternion.Euler(xRot, yRot, 0);
}
So i drag down my finger (or mouse) and when X goes to 90 or -90, Y axis becomes 0 and Z axis begins to rotate (which is not expected). And the thing is that if i continue to drag down my finger (or mouse), Z axis also continues to change. And i have to drag back the same amount of time!
So if X is already -90 and i make 2 more drags down, i will have to make 2 drags up before player starts to rotate back.
I hope i explained it good enough.