Hey folks,
I am trying to finish my car game with some fancy calculations, so I decided to bring up a stunting-system.
I am guessing that the other flip-directions are structured the same, so here is the code only for the frontflip:
var rot : Vector3; //<- Declarated at the top of the script
if(transform.eulerAngles.x > rot.x){
rot.x = transform.eulerAngles.x;
if(rot.x >= 90 && rot.x < 100 && !rot90){
rot90 = true;
score += 900;
}
if(rot.x >= 180 && rot.x < 190 && rot90 && !rot180){
rot180 = true;
score += 1800;
}
if(rot.x >= 270 && rot.x < 280 && rot180 && !rot270){
rot270 = true;
score += 2700;
}
if(rot.x > 359 && rot270 && !rot360){
rot360 = true;
score += 3600;
rot.x = 0;
return;
}
} else {
rot90 = false;
rot180 = false;
rot270 = false;
rot360 = false;
rot.x = 0;
}
For testing purposes I turned UseGravity off and add a RotateAround x-rotation to simulate.
The eulerAngles are a bit problematic because I realized when the car’s rotation has reached 90 it reverses the value from 90 to 270 (decreasing value) and when it has reached 270 it goes again back to 90 (increasing value) although the car physically rotates constantly to positive x.
This does not make sense to me, because then the car would be rotating like a windshield wiper.
Any help is appreciated!