My current script rotates a part of the player. However the rotation is very choppy and instant. This is especially bad when using an analog stick for control, as it seems to be pretty on/off in it’s movement. How would I go about smoothing the movement, so that it would be less choppy on both keyboard and gamepad controls, and take into account the degree to which the analog stick is tilted?
public float speed = 6f;
private float minRot = -0.35f;
private float maxRot = .35f;
public float rotation;
void Update()
{
if (Input.GetAxisRaw("Aim") < 0)
{
rotation += speed * 0.1f * Time.deltaTime;
}
if (Input.GetAxisRaw("Aim") > 0)
{
rotation -= speed * 0.1f * Time.deltaTime;
}
rotation = Mathf.Clamp(rotation, minRot, maxRot);
Quaternion rot = transform.localRotation;
rot.z = rotation;
transform.localRotation = rot;
}