si0ty
1
Hey Guys. I wan’t to add one point to back- or frontflip only once:
if (deltaRotation >= 300) {
deltaRotation -= 360;
}
if (deltaRotation <= -300) {
deltaRotation += 360;
}
WindupRotation += (deltaRotation);
flips = WindupRotation / 360;
if (flips < 0) {
frontFlip++; }
if (flips > 0) {
backFlip++;
}
It’s adding a point every frame so I tried Time.deltaTime in several ways but it didn’t work. What’s the best way here to just get one point for every rotation done?
If you don’t need “WindupRotation” for anything else than counting front / back flips, you can simply do this:
if (flips < 0) {
WindupRotation += 360;
frontFlip++;
}
if (flips > 0) {
WindupRotation -= 360;
backFlip++;
}
If you want to keep the net rotation angle you can introduce a reference flip count in a similar way:
private int flipCount = 0;
if (flips < flipCount) {
flipCount--;
frontFlip++;
}
if (flips > flipCount) {
flipCount++;
backFlip++;
}
So as soon as “flips” is greater than the reference “flipCount” we have another flip so we adjust flipCount to match flips. From your code it’s not clear what variable types you’re using. However “flips” should be an integer. If “WindupRotation” is a float, you should do:
flips = (int)(WindupRotation / 360);