Guest User

Untitled

a guest
Jan 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. @name HK-drone chip
  2. @inputs RPod:entity LPod:entity APod:entity Pod:wirelink
  3. @outputs RThrust LThrust AThrust
  4. #These persists are for the 3 thruster pod's pitches
  5. @persist RPitch LPitch APitch
  6. #these persists are for calculation the height
  7. @persist ZOffset Altitude
  8. #these persists are the angles and motion of the body of the craft
  9. @persist Roll Pitch AngVel ForwardVel SideVel
  10. #these persists are needed for countering some motions
  11. @persist SpeedCounter SpinCounter
  12. #Torque
  13. @persist Torque
  14.  
  15. interval(50)
  16.  
  17. if(first() | duped()){
  18. Altitude=entity():pos():z()
  19. #Torque is the strength of the pod rotation
  20. Torque=70
  21. Altitude=entity():pos():z()
  22. gSetGroup("E_Debugger")
  23. gShare(1)
  24.  
  25. }
  26.  
  27.  
  28. if(gGetNum("HKDroneDrivable")==1){
  29. selfDestruct()
  30. }
  31.  
  32. ###Adv. Pod contrller Wirelinks ----------------------------------------------------
  33. #(depreciated look on the expression 2 wiki for updates)
  34.  
  35. Active=Pod:number("Active")
  36. W=Pod:number("W")
  37. A=Pod:number("A")
  38. S=Pod:number("S")
  39. D=Pod:number("D")
  40. Mouse1=Pod:number("Mouse1")
  41. Mouse2=Pod:number("Mouse2")
  42. Space=Pod:number("R")
  43. Shift=Pod:number("Space")
  44. Alt=Pod:number("Alt")
  45. Driver=Pod:entity("Entity"):driver()
  46. AimPos=Pod:vector("AimPos")
  47. Bearing=Pod:number("Bearing")
  48. Elevation=Pod:number("Elevation")
  49.  
  50.  
  51.  
  52. ###Minimum Height----------------------------------------------------
  53. #Use E2 ranger to find the ground so it won't "try" to go below it
  54. #The ranger filter is so it won't detect the body since the ranger/E2 is on top
  55. rangerHitWater(1)
  56. rangerFilter(entity():isWeldedTo())
  57. RD=rangerOffset(9999999,entity():pos(),vec(0,0,-1))
  58. Ground=RD:position():z()+40
  59.  
  60. ###Flying Altitude----------------------------------------------------
  61. #This if statement will reset the calculated altitude so it won't fly up when you turn it on
  62. if(!Active){
  63. #Altitude=entity():pos():z()
  64. }
  65.  
  66. #Anything following this will not happen unless you activate the pod controller
  67. #if(Active){
  68.  
  69. #These if statements increase or decrease the craft's height
  70. #Change the 3 to something higher to increase climb/decend rate
  71. if(Shift){
  72. Altitude=Altitude+6
  73. }elseif(Space){
  74. #print("alt decrease")
  75. Altitude=Altitude-6
  76. }
  77.  
  78. ###Maintain Altitude----------------------------------------------------
  79. #this section will calculate how much thrust is needed to get up to the target altitude
  80. RealZ=entity():pos():z()
  81. ZOffset=(Altitude-RealZ)
  82. HoverThrust=(ZOffset+$ZOffset*10)*1
  83.  
  84. ###Hover Balance----------------------------------------------------
  85. #These lines are what keep the craft upright (no keep upright stool)
  86. #They only affect the strength of the thrusters
  87. Angles=entity():angles()
  88. Roll=Angles:roll()
  89. Pitch=Angles:pitch()
  90. RollCounter=(Roll+$Roll*3)*3
  91. PitchCounter=(Pitch+$Pitch*2)*5
  92.  
  93. ###Counter Movement----------------------------------------------------
  94. #The next 3 lines find the velocities (and/or accelerations with $)
  95. ForwardVel=entity():velL():x()
  96. SideVel=entity():velL():y()
  97. AngVel=entity():angVel():yaw()
  98. #The if statements keep it from countering it's own desired movement
  99. if(W|S){
  100. SpeedCounter=0
  101. }else{
  102. SpeedCounter=(ForwardVel+$ForwardVel*0)/12
  103. }
  104. if(A|D){
  105. SpinCounter=0
  106. }else{
  107. SpinCounter=(AngVel+$AngVel*0)/3
  108. }
  109. #And StrafeCounter stops side to side sliding motion
  110. #StrafeCounter and RollCounter affect each other because it increases its roll
  111. #in order to stop strafing
  112. StrafeCounter=(SideVel+$SideVel*1)/1.5
  113.  
  114. ###Thruster thrust----------------------------------------------------
  115. #These lines put all of the required calculations that can be changed by the pods' thrust
  116. #strength (like hover height
  117. RThrust=clamp((HoverThrust/cos(Pitch))+RollCounter-StrafeCounter,0,50)
  118. LThrust=clamp((HoverThrust/cos(Pitch))-RollCounter+StrafeCounter,0,50)
  119. AThrust=clamp(HoverThrust/cos(Pitch)-PitchCounter,0,50)
  120.  
  121. ###Angle of Thruster Pods--------------------------
  122. #these 2 lines change the angle of the pods for moving
  123. GoAngle=40*(S-W)
  124. TurnAngle=20*(D-A)
  125. #These next 3 lines put all of the requred calculations that can be changed by the pods'
  126. #angles (like turning and forward/backward movement and counter movment)
  127. RPitch=clamp(RPod:angles():pitch()+GoAngle+TurnAngle+SpeedCounter+SpinCounter,-160,160)
  128. LPitch=clamp(LPod:angles():pitch()+GoAngle-TurnAngle+SpeedCounter-SpinCounter,-160,160)
  129. APitch=clamp(APod:angles():pitch()+GoAngle+SpeedCounter,-160,160)
  130. #Then use applyAngForce to change the angle of the pods in only the Pitch
  131. RPod:applyAngForce(ang(RPitch+$RPitch*4,0,0)*Torque)
  132. LPod:applyAngForce(ang(LPitch+$LPitch*4,0,0)*Torque)
  133. APod:applyAngForce(ang(APitch+$APitch*4,0,0)*Torque)
  134.  
  135.  
  136. #}
  137. #else{
  138. #The rest of this junk just makes the thrusters level with the craft when turned off
  139. # RPitch=RPod:angles():pitch()
  140. # LPitch=LPod:angles():pitch()
  141. # APitch=APod:angles():pitch()
  142. # RPod:applyAngForce(ang(RPitch+$RPitch*4,0,0)*20)
  143. # LPod:applyAngForce(ang(LPitch+$LPitch*4,0,0)*20)
  144. # APod:applyAngForce(ang(APitch+$APitch*4,0,0)*20)
  145. # RThrust=0
  146. # LThrust=0
  147. # AThrust=0
  148. #}
  149.  
  150. #original code credited to mike_dude
Add Comment
Please, Sign In to add comment