Topic was automatically imported from the old Question2Answer platform.
Asked By
AeromechanicalAce
My project utilizes an Isometric Camera, and am attempting to write a function that checks what direction the camera is pointing and display that as a string. The script to rotate the camera rig is functioning correctly, and rotates the camera in 90 degree increments.
func Check_Orientation():
if rotation_degrees.y == 0 or 360:
Camera_Orientation = “NE”
if rotation_degrees.y == 90 or -270:
Camera_Orientation = “NW”
if rotation_degrees.y == 180 or -180:
Camera_Orientation = “SW”
if rotation_degrees.y == 270 or -90:
Camera_Orientation = “SE”
else:
Camera_Orientation = “???”
This function is called every time the command to rotate the camera is given.
Despite running the function on Ready, the display starts off on the ??? option (It begins at 0, so it SHOULD be displaying Northeast), and will only display Southeast, regardless of what direction the camera is actually pointing.
I’d guess you’re being bitten by a number of issues (floating point equality, general code syntax, and logic). First, it’s NEVER a good idea to use exact equality checks against floating point numbers as such checks will routinely fail.
You could try to replace your equality checks with calls to is_equal_approx() instead, which is designed to combat such issues.
For example, rather than this:
if rotationdegrees.y == 0 or 360
You use something like:
if is_equal_approx(rotation_degrees.y, 0) or is_equal_approx(rotation_degrees.y, 360):
# do stuff...
(also, note that your or syntax (0 or 360) isn’t doing what you intend. That needs to be broken into two separate or statements.
Docs here:
Just noticed that else statement isn’t what you want either as it’s only paired with the last if statement… Untested, but something like this might be closer to what you need…