- Home /
How to properly do Twin Stick shooter controls with an XBOX controller?
Pretty much what the title says, I was using this bit of code:
void Update () {
float leftStickx = Input.GetAxis("Horizontal");
float leftSticky = Input.GetAxis("Vertical");
transform.Translate(leftStickx * Time.deltaTime * speed, leftSticky * Time.deltaTime * speed, 0, Space.World);
float rightStickx = Input.GetAxis("Right_Horizontal");
float rightSticky = Input.GetAxis("Right_Vertical");
float angle = Mathf.Atan2(rightStickx, rightSticky) * Mathf.Rad2Deg;
if (rightStickx != sensitivity || rightSticky != sensitivity)
{
transform.rotation = Quaternion.EulerAngles(0.0f, 0.0f, angle);
// transform.rotation = Quaternion.Angle()
}
}
from a tutorial, but #1 EulerAngles seem to be deprecated, which is okay, but it still rotated my character, even if the sensitivity was crazy. So, how do I use the Quaternion.Angle with an XBOX Right Thumbstick so I can rotate my character and do it smoothly.
Thanks a lot for any help in this matter!
Answer by Zodiarc · Oct 28, 2016 at 09:26 AM
You would need to use Quaternion.Lerp.
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.EulerAngles(...), rotationSpeed * Time.deltaTime)
That did not work, but thank you very much for answering.
Using an XBOX controller for a twin stick shooter.
If at all possible, would love to get rid of the deprecated code anyway, but if not, would like to have it be a bit more smooth in the rotation.
Failing that, it would be nice to get rid of the gimbal lock or whatever is causing the bugged rotations at some 90degree angles.
Your answer
Follow this Question
Related Questions
90 Degree stopping rotation on y-axis issue 0 Answers
How to get angular difference? 2 Answers
Align GameObject to Terrain angle 2 Answers
Creating a multiple part turret what locks onto certain axis. 4 Answers