# Controller Axes Rotational Input

Hey i’m currently working on a skateboarding game and am trying to figure out the input for when the controller stick rotates around the perimeter of the game pad. It’s for the start of pop shuv it tricks. Here are the motions i’m trying to map.

Thanks

[12736-screen+shot+2013-07-02+at+4.03.05+pm.png|12736]

You will have to measure and cache controller stick positions in your Update loop. You can use Input.GetAxis(“Horizontal”) and Input.GetAxis(“Vertical”) to get the x and y positions. By tracking many of these over time, you can analyze the pattern of motion. For instance, you’ll know if the user has done a down stroke on the thumbstick if the current position is at the bottom, and the previous x positions were similar (within some threshhold) and y positions were trending down.

Here is a script that implements an immediate rotation. It expects the camera looking towards positive ‘Z’ and the rotates around the ‘Z’ axis. And it is a relative rotation, not an absolute rotation.

``````#pragma strict

private var rotating = false;
private var prevAngle = 0.0;

function Update() {
var horz = Input.GetAxis("Horizontal");
var vert = Input.GetAxis("Vertical");
if (rotating) {
if (Mathf.Abs(horz) < 0.99  && Mathf.Abs(vert) < 0.99) {
rotating = false;
return;
}
var angle = Mathf.Atan2(vert, horz) * Mathf.Rad2Deg;
transform.Rotate(0.0, 0.0, -(angle - prevAngle));
prevAngle = angle;
}
else {
if (Mathf.Abs(horz) > 0.99 || Mathf.Abs(vert) > 0.99) {
prevAngle = Mathf.Atan2(vert, horz) * Mathf.Rad2Deg;
rotating = true;
}
}
}
``````

As expected, for my controller there are little dead zones. It works fine for brisk movements, but it is jerky for slow movements due to the dead zones.