# Smooth rotation of object with gamepad stick.

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;
}
``````

You are most of the way there. The trick is to just directly use Input.GetAxisRaw to multiply the rotation by, as this will actually give you a larger or bigger value based on how far you moved the joystick:

``````void Update()
{
rotation -= Input.GetAxisRaw("Aim") * speed * 0.1f * Time.deltaTime;

rotation = Mathf.Clamp(rotation, minRot, maxRot);
Quaternion rot = transform.localRotation;
rot.z = rotation;

transform.localRotation = rot;
}
``````

Note that you will likely need to adjust your speed value to compensate.

As a side note I would say that it is redundant to multiply both by speed, and by the fixed value of 0.1f:

``````rotation += Input.GetAxisRaw("Aim") * speed * 0.1f * Time.deltaTime;
``````

Personally I would remove the 0.1f and just set your value for speed lower:

``````//at the top:
public float speed = 0.6f;
//in update:
rotation += Input.GetAxisRaw("Aim") * speed * Time.deltaTime;
``````