Hello,
I’ve been struggling with this issues now for ages and can’t find a solution.
I have an object pointing in the y-axis… when I rotate it around the X axis I want to return an angle between 0 and 360.
Therefore I got this script:
def update(self):
rotX = math.degrees(self.object.localOrientation.to_euler().x)
if not self.object[“flipped”]:
if rotX < 0:
rotX += 360
else:
pass
print(rotX)
Now if I turn the object around its Z Axis 180° the script doesnt work anymore.
I get completely wrong values.
Can someone help me solving this issue?
I’m attaching an example blend in upbge 0.25.
When you rotate the object with W-Key you get values from 0-360°
All good.
Then, when you rotate the object with SPACE 180° on the Z, the returned values jump from 90 to 270 and are off.
I’m unable to find a fix for that.
I went the dot product route but that didn’t help either.
You mean the solution from discord?
I repost here for others:
"
Here’s a solution where I calculate the angle between the local_z axis to world Z-axis but it is only correct if you don’t have an additional rotation around the y-axis.
yeah, thanks musikai. Your solution almost works but there were still some jumping. So for now, I just lerped to conceal the problem, which is OK.
Also had to use a different formula for when the player is rotated normal.
self.stance is 0 Z rotation and not self.stance is 180° Z rotation