- Home /
How to check if an object has rotated around itself (360° in x,y,z)
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!
Answer by Rostam24 · Oct 06, 2015 at 10:11 AM
Maybe the easiest solution would be to check for a 90, 180, 270 and >359 degree rotation (which is a rotation in one direction), as well as a 270, 180, 90 and <1 degree rotation (which is a rotation in the other direction).
So a 360 degree rotation (the first one) would only count if the car first rotated 90, then 180, and then 270 degrees. This way small amounts of rotation in either direction won't result in any points.
Thanks for your answer, Rostam24! Yeah, this is a good point to query the rotation like that.
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.
Long shot, but what happens when you set gravity and drag to 0 and cause rotation using physics ins$$anonymous$$d?
Again, nothing happens. I have updated the code. :D
Your answer
Follow this Question
Related Questions
2d detect 360 (backflip) rotation on z axis? 2 Answers
How to check if a car has perform stunt? 0 Answers
Flip over an object (smooth transition) 3 Answers
Don't understand how to use DontDestroyOnLoad. 2 Answers
Storing high score 2 Answers