Mirror joystick direction to always be upwards?

Solved

So kind of an odd problem I got here.

Basically i want the joystick to mirror the direction its being pointed in. Lets say if the joystick is pointing downwards it will instead be pointing upwards or if the joystick is facing the to the bottom right it will flip the direction and point to the top right instead.

Pretend the green arrow is the real direction the joystick is pointing and the red arrow is what it should be


I’ve tried to do this by myself to no avail. This is what I tried.


import bge
import bge, math, time
from mathutils import Vector


cont = bge.logic.getCurrentController()
own = cont.owner
Obj = own
ori = Obj.orientation.to_euler()
Obj["ori_prop"] = str(ori)
oriDeg = math.degrees(ori[2])
Obj["oriDeg_prop"] = oriDeg
joy = cont.sensors["Joystick"]


# Vars
limit = 32768.0
jx = joy.axisValues[0]/limit
jy = joy.axisValues[1]/limit
jxInvert = joy.axisValues[0]/limit
jyInvert = joy.axisValues[1]/limit
deadzone = .3


def main():


    if max(abs(jx), abs(jy)) >= deadzone:
        
        if 90 > oriDeg > -90:
            ang = math.atan2(-jx, -jy)
            ori.z = ang 
            Obj.orientation = ori
            print("inbetween 90 and -90!")
            
        else:
            ang = math.atan2(-jxInvert, jyInvert)
            ori.z = ang 
            Obj.orientation = ori        
            


main()

T̶h̶e̶ ̶r̶e̶s̶u̶l̶t̶ ̶w̶a̶s̶ ̶"̶s̶e̶m̶i̶-̶r̶i̶g̶h̶t̶"̶ ̶t̶h̶e̶ ̶o̶b̶j̶e̶c̶t̶ ̶w̶o̶u̶l̶d̶ ̶f̶l̶i̶c̶k̶e̶r̶ ̶b̶e̶t̶w̶e̶e̶n̶ ̶u̶p̶ ̶r̶i̶g̶h̶t̶ ̶a̶n̶d̶ ̶m̶i̶r̶r̶o̶r̶e̶d̶ ̶p̶o̶s̶i̶t̶i̶o̶n̶s̶ ̶e̶v̶e̶r̶y̶ ̶f̶r̶a̶m̶e̶ ̶:̶/̶
I̶s̶ ̶t̶h̶e̶r̶e̶ ̶a̶ ̶b̶e̶t̶t̶e̶r̶ ̶w̶a̶y̶ ̶t̶o̶ ̶a̶c̶h̶i̶e̶v̶e̶ ̶t̶h̶i̶s̶ ̶e̶f̶f̶e̶c̶t̶?̶ ̶D̶o̶i̶n̶g̶ ̶t̶h̶i̶s̶ ̶s̶h̶o̶u̶l̶d̶ ̶f̶i̶x̶ ̶t̶h̶e̶ ̶p̶r̶o̶b̶l̶e̶m̶ ̶I̶ ̶h̶a̶v̶e̶ ̶w̶h̶e̶n̶ ̶t̶h̶e̶ ̶c̶h̶a̶r̶a̶c̶t̶e̶r̶ ̶r̶u̶n̶s̶ ̶a̶t̶ ̶t̶h̶e̶ ̶c̶a̶m̶e̶r̶a̶ ̶a̶n̶d̶ ̶s̶p̶a̶z̶e̶s̶ ̶o̶u̶t̶ ̶d̶i̶f̶f̶e̶r̶e̶n̶t̶ ̶d̶i̶r̶e̶c̶t̶i̶o̶n̶s̶

EDIT:
Fixed! The solution is instead of using the degrees for rotation, you use the joysticks direction and when jx is inbetween .99 and 1 aswell as jy being > 0 you invert the jy vector.


import bge
import bge, math, time
from mathutils import Vector


cont = bge.logic.getCurrentController()
own = cont.owner
Obj = own
ori = Obj.orientation.to_euler()
joy = cont.sensors["Joystick"]


# Vars
limit = 32768.0
jx = joy.axisValues[0]/limit
jy = joy.axisValues[1]/limit
deadzone = .3


def main():


    if max(abs(jx), abs(jy)) >= deadzone:
          
        if .99 > jx > -1.00 and jy > 0:
            ang = math.atan2(-jx, jy)
            ori.z = ang 
            Obj.orientation = ori
            
        else:
            ang = math.atan2(-jx, -jy)
            ori.z = ang 
            Obj.orientation = ori        


main()