- Home /
Getting full rotation while in the air
I have a script that lets the player rotate on the y axis while it is in the air. I am trying to get the total amount of rotation while in the air. It seems that once the global rotation of the object exceeds 360 degrees, it resets back to 0, so I get inaccurate results. The player has a character controller if that somehow matters. Here is my code:
Move:
transform.Rotate(0,turnit, 0);
Get rotation:
var controller : CharacterController = GetComponent(CharacterController);
/////////////// 360 /////////////////
if (controller.isGrounded == false) {
if (canStartChecking == true) {
three_sixty();
}
}
if (controller.isGrounded) {
if (canStartChecking == false) {
canStartChecking = true;
rotY2 = transform.rotation.eulerAngles.y;
fullRot = Mathf.Abs(rotY2 - rotY);
//Debug.Log(fullRot);
if (fullRot > 160 && fullRot < 200) {
Debug.Log("180!");
}
if (fullRot > 340 && fullRot < 380) {
Debug.Log("360!");
}
}
}
//////////////// END OF 360 ////////////////
}
function three_sixty () {
canStartChecking = false;
rotY = transform.rotation.eulerAngles.y;
var controller : CharacterController = GetComponent(CharacterController);
}
I realize some of this is probably bad code, but its not final. Thanks in advance!
$$anonymous$$aybe you could get the delta rotation that your object rotates by each frame and add those deltas up (or add up their absolute value) to get the amount you have rotated in the air. Alternatively you could set some tolerance point, which if reached you add 1 to a 'rotations' variable and then start counting again for the next full rotation
Answer by FlaSh-G · Aug 29, 2014 at 09:45 PM
Simply don't read the object's rotation. Whenever you rotate:
transform.Rotate(0, angles, 0);
angleCounter += angles;
Then read angleCounter (which should be an instance variable of type float).