@name UFO
@inputs [Num Dual1 Dual2]:wirelink 
@outputs HoverFR HoverFL HoverRR HoverRL Hover Angles:angle Rot UpDn Pon
@outputs RLThruster FBThruster Turn Roll Pitch Keyboard
@model models/props_junk/PopCan01a.mdl
@persist
@trigger 
interval(10)




O=owner()
Chat=O:lastSaid()
if(Chat:find("Joybot K")){Keyboard=1}
if(Chat:find("Joybot J")){Keyboard=0}
    

N0 =   Num["0",number]
N1 =   Num["1",number]
N2 =   Num["2",number]
N3 =   Num["3",number]
N4 =   Num["4",number]
N5 =   Num["5",number]
N6 =   Num["6",number]
N7 =   Num["7",number]
N8 =   Num["8",number]
N9 =   Num["9",number]
Slash= Num["/",number]
Astrix=Num["*",number]
Minus= Num["-",number]
Plus=  Num["+",number]
Enter= Num["enter",number]
Del=   Num[".",number]

Yup=Dual1["A",number]>0
Ydown=Dual1["A",number]<0
Xleft=Dual2["A",number]>0
Xright=Dual2["A",number]<0
Rright=N6
Rleft=N4
Zup=N8
Zdown=N2
B5=Slash
B6=Del
B7=Enter
B8=Plus
Hleft=N7
Hright=N9
B11=Astrix

#Angles=entity():angles()
#A=50 #degrees at which the joystick will invert and bounce back.
#Pon=-(Angles:pitch()>A)-(Angles:pitch()<-A)+(Angles:pitch()<A)+(Angles:pitch()>-A)

R=0.5
RLThruster=(Xleft-Xright)*500
FBThruster=(Yup-Ydown)*500*(10*B6+!B6)
Turn=(-Rright+Rleft)*150*(R*!Hover+Hover)
Pitch=(Zup-Zdown)*300
Roll=(Hleft-Hright)*600




Rot=(Zup-Zdown)*R
UpDn=(B8-B7)*(B6*5+!B6)


HoverFR=(UpDn+Rot-(Hright-Hleft)*(R/2))
HoverFL=(UpDn+Rot-(-Hright+Hleft)*(R/2))
HoverRR=(UpDn-Rot-(Hright-Hleft)*(R/2))
HoverRL=(UpDn-Rot-(-Hright+Hleft)*(R/2))




if(B11){Hover=!Hover}


