Last active
February 26, 2019 03:42
-
-
Save mkjiau/bf82be37d90698e6998b56204bc30b02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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