Skip to content

Instantly share code, notes, and snippets.

@mkjiau
Last active February 26, 2019 03:42
Show Gist options
  • Save mkjiau/bf82be37d90698e6998b56204bc30b02 to your computer and use it in GitHub Desktop.
Save mkjiau/bf82be37d90698e6998b56204bc30b02 to your computer and use it in GitHub Desktop.
public float totalChange = 0;
public float lastAzimuth = -1000;
public int r_count = 0;
private void FixedUpdate()
{
if (joycons.Count > 0)
{
Joycon j = joycons[jc_ind];
float rotatation = j.GetVector().eulerAngles.y;
//if (init_rotation == 0f || rotatation == -1)
//{
// init_rotation = rotatation;
// return;
//}
float diff;
float az = rotatation;
if (az > 180) az -= 360; // do this if your azimuth is always positive i.e. 0-360.
if (lastAzimuth == -1000)
{
lastAzimuth = az;
}
diff = az - lastAzimuth;
if (diff > 180)
diff -= 360;
if (diff < -180)
diff += 360;
lastAzimuth = az;
totalChange += diff;
r_count = Convert.ToInt32(totalChange / 360); // CountTurns
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment