you might be running afoul of the fact that a quaternion converted into a euler representation could be many values, i.e. 0, 360, -360 are all the same angle.
Hullo!
Probably means that test == 50.
The operators <= and >= mean “less than or equal to” and “greater than or equal to,” respectively. The only way both statements would evaluate to true would be if test is, well, equal to 50. I would suggest printing the actual test value or exposing it via the inspector or something to check what the actual value is.
There must be an overlooked detail derailing expectations then…
You are assigning vehicleTransform.localEulerAngles.z to a var test and testing that, but you say you are printing vehicleTransform.localEulerAngles.z (which is printing different values) but not printing test. Drilling down to the core issue would likely be alot easier if you posted the entire script.
It’s most likely the issue that @LeftyRighty has already pointed out.
@Fillock
While not in playmode, the rotation shown in the editor can exceed the range of 0-360 into both directions, negative and positive.
However, during playmode/runtime, the values will be kept in the range of 0-360 (360 exclusiv of course), probably due to floating imprecision, otherwise you’d run into some ugly problems when an object keeps rotating all the time and reaches much higher values.
If your car happens to drive down (or up, that depends on the setup) a hill, the or orientation would theoretically be a negative number, but remember, Unity keeps it in a certain range. Imagine you’ve got a z-orientation of -50 degrees, Unity will make 310 out of it and the code you’re using won’t work as expected. This also applies for values >= 360.
Shure I post the hole script. Here I diged out the code from the carscript:
#
#pragma strict
var vehicleTransform : Transform;
function Update () {
var test = vehicleTransform.localEulerAngles.x;
// print (test); // in runtime this works, 360 the car on flat ground
if (test >= 310) {
TireSlidingDown();
}
if (test <= 50) {
TireSlidingUpp();
}
}
function TireSlidingDown() {
print ("Driving Upphill");
}
function TireSlidingUpp() {
print ("Driving Downhill");
}
It work some kind of way, driving upphill it print "Driving Upphill"l and driving downhill it print “Driving Downhill”. But on flat land its allways printing, it never stop.
If you haven’t flipped anything around, flat land means ~0 +/- something. That’s always covered by the conditions, if it’s 0 or greater the second one will trigger, if it’s therotical below 0 it’s gonna turn into 3xx and the first one will match.
You could add another condition to each as a threshold, so that you define a range of 310-340 and 20-50 for example.
No, like the example that i had given. The one that you posted cannot work because a number can never be greater than 300 and smaller than 0 at the same time.