- Home /
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
I'm not sure this can be done. In particular run this code using your joystick:
function Update() {
var horz = Input.GetAxisRaw("Horizontal");
var vert = Input.GetAxisRaw("Vertical");
Debug.Log(horz+","+vert);
}
What I see are values which remain the same around significant portions of the rotation. You could implement a clunky rotation, or a clunky rotation with smoothing, but I don't see how to get smooth, real-time analog input for this motion. What you want is unique x,y values from each position around the circle.
cool i did that... one value always is changing. i brought the controller down and did a full 360 around the outside perimeter. I think a rough rotation could be made. 0,0 0,-0.03728097 0,-0.07196278 0,-0.0990991 -0.06695437,-0.0990991 // start of rotation 0.3683774,-0.09050578 0.3780917,-0.08741732 0.2517123,-0.08672997 0.1642821,-0.08672997 -0.07666886,-0.09290995 -0.1641905,-0.09565628 -0.3390507,-0.0990991 -0.5625747,-0.0990991 -1,-0.0977183 -1,-0.06647014 -1,-0.03281781 -1,-0.003628639 -1,0.04244062 -1,0.06544982 -1,0.07540561 -1,0.07918447 -1,0.08742648 -1,0.08811077 -1,0.09188963 -0.8444771,0.09601063 -0.5237169,0.09704012 0.05733136,0.09841481 0.2905699,0.09841481 0.7570469,0.09841481 1,0.09806961 1,0.09291911 1,0.08811077 1,0.07712244 1,0.06441729 1,0.04896581 1,0.02595966 1,-0.0115285 1,-0.04174718 1,-0.07951745 1,-0.08054694 1,-0.09462678 //end of rotation
so this is clearly a pretty rough circle around with inconstant speeds. one of the values is constantly changing. What i need to do is take rough estimates of these values and connect them. I'm clueless on how to implement it but i know i need to make gates where if the input passes though all gates in a set amount of frames the trick is thrown. How would i make those gates?
Thanks, Andrew
$$anonymous$$y controller did not have the values changing like this, so I'm concerned that this solution may only work with some controllers. As a starting point you might try $$anonymous$$athf.Atan2() and see how far off the angles are from what you want:
angle = $$anonymous$$athf.Atan2(vert, horz) * $$anonymous$$athf.Rad2Deg;
One possible reason for the different values is that $$anonymous$$e was in a fixed update. Im currently using an xbox 360 controller but will try it with a ps3 controller once i get one hooked up soon. As far as the mathf.atan2 it returned 0 to 180 on the x axes and 5 to 175 on the y axes with the xbox 360 conch. ill most likely be able to test a ps3 conch tommorow and an ouya conch if they released mac drivers.
If I do this with my controller:
function Update() {
var horz = Input.GetAxisRaw("Horizontal");
var vert = Input.GetAxisRaw("Vertical");
var angleT = $$anonymous$$athf.Atan2(vert, horz) * $$anonymous$$athf.Rad2Deg;
Debug.Log(angleT);
}
I get values from -179 to 180 that map to a left-hand coordinate system rotation of the joystick. For me there are areas that don't change so the rotation values are not smooth. If you are trying for brisk movements, it might work.
Answer by ebogguess · Jul 02, 2013 at 10:33 PM
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.
Thanks for answering. I have been tracking the positions. What im still clueless about is linking it all together by checking what the previous positions were . Right now i have it where if the vertical axes is less then -.09 do this. I need it to say if the axes are at zero and then go to -.09 do this.
Answer by robertbu · Jul 03, 2013 at 02:11 AM
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.
This is certainly helpful. The problems are that it returns true for rotation even if a simple x axes move is made and it returns true for all rotations when I only need rotations on the outside perimeter . But it's definitely a helpful start. There is alot of power in $$anonymous$$athf.Atan2 and I believe once I figure out how to track input over multiple frames (in ebogguess answer) i should be able to get solid code that achieves what is needed. Im gonna get to the bottom of this tomorrow.
Thanks a ton
If it is returning true for all rotations, then you need to decrease your Sensitivity setting in the Input$$anonymous$$anager for Horizontal and Vertical. Comparing 'horz' and 'vert' to 0.99 in the code above is to assure the joystick is towards the outside. For my joystick, I have the Sensitivity set to 1.5 for both Horizontal and Vertical. Do a 'Debug.Log(horz+","+vert)' and exa$$anonymous$$e where on your stick motion do horz and vert go to 1/-1.
Your answer
![](https://koobas.hobune.stream/wayback/20220613105352im_/https://answers.unity.com/themes/thub/images/avi.jpg)