Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. @name Drone Only Flight
  2.  
  3. @inputs RPod:entity LPod:entity APod:entity
  4.  
  5. @outputs RThrust LThrust AThrust
  6.  
  7.  
  8. @persist RPitch LPitch APitch TargetZ Altitude Roll Pitch Stablize
  9. @persist LTorque:vector RTorque:vector ATorque:vector
  10. @persist AngVel ForwardVel SideVel SpeedCounter SpinCounter UpsideDown
  11. @persist Bearing Follow:vector Active
  12. @persist Go BearingToFollow FlippedOff
  13.  
  14. runOnChat(1)
  15. interval(20)
  16.  
  17. function number getGroundPosition(){
  18. rangerHitWater(1)
  19. rangerFilter(entity():isWeldedTo())
  20. RD = rangerOffset(9999999,entity():pos(),vec(0,0,-1))
  21.  
  22. return RD:position():z()+0
  23. }
  24.  
  25. if(first()|duped()){
  26. Torque=120 #120 normally
  27. Altitude=entity():pos():z()
  28. }
  29.  
  30. Follow=entity():owner():pos()
  31. BearingToFollow=entity():bearing(Follow)
  32.  
  33. ###Maintain Altitude
  34.  
  35. Altitude=clamp(Follow:z()+200,getGroundPosition(),999999999)
  36. TargetZ = (-entity():pos():z() + Altitude)
  37. HoverThrust=(TargetZ+$TargetZ*15)*2
  38.  
  39. DistanceOfTarget = entity():pos():setZ(0):distance(Follow:setZ(0))
  40. if(TargetZ>100){
  41. }
  42. elseif(DistanceOfTarget>300){
  43. Go=clamp((DistanceOfTarget-300)*1.5/300,-1,1)
  44. }
  45. else {
  46. Go=-0.02
  47. }
  48.  
  49. ###Angle of Thruster Pods
  50.  
  51. if (Pitch>75 || abs(Roll)>90) {
  52. UpsideDown=-1
  53. FlippedOff=0
  54. APitch=entity():angles():pitch()
  55. }
  56. elseif (Pitch<-30) {
  57. APitch=-entity():angles():pitch()
  58. Stablize=0
  59. }
  60. else {
  61. UpsideDown=1
  62. FlippedOff=1
  63. Stablize=1
  64. APitch=clamp((FlippedOff*Stablize*(SpeedCounter)),-90,90)
  65. }
  66.  
  67. #RPitch=clamp((FlippedOff*(SpeedCounter+SpinCounter)),-90,90)
  68. #LPitch=clamp((FlippedOff*(SpeedCounter-SpinCounter)),-90,90)
  69.  
  70. Rotation = ang(-RPitch,0,0)
  71. Local = RPod:toLocal(vec(0,0,-1) + RPod:pos())
  72. RTorque = (vec(0,0,1):rotate(Rotation):cross(Local) * 400 - RPod:angVelVector() * 1/3) * vec(0,RPod:inertia():y(),0)
  73. RPod:applyTorque(RTorque*130)
  74.  
  75. Rotation = ang(-LPitch,0,0)
  76. Local = LPod:toLocal(vec(0,0,-1) + LPod:pos())
  77. LTorque = (vec(0,0,1):rotate(Rotation):cross(Local) * 400 - LPod:angVelVector() * 1/3) * vec(0,LPod:inertia():y(),0)
  78. LPod:applyTorque(LTorque*130)
  79.  
  80. Rotation = ang(-APitch,0,0)
  81. Local = APod:toLocal(vec(0,0,-1) + APod:pos())
  82. ATorque = (vec(0,0,1):rotate(Rotation):cross(Local) * 400 - APod:angVelVector() * 1/3) * vec(0,APod:inertia():y(),0)
  83. APod:applyTorque(ATorque*130)
  84.  
  85. ###Hover Balance
  86.  
  87. Angles=entity():angles()
  88. Roll=-Angles:roll()
  89. Pitch=Angles:pitch()
  90. RollCounter=(Roll+$Roll*3)*10
  91. PitchCounter=(Pitch+$Pitch*4)*3.5-25
  92. StrafeCounter=(SideVel+$SideVel*0.25)/3
  93.  
  94. RThrust=clamp(FlippedOff*((HoverThrust/cos(RPitch))-RollCounter-StrafeCounter),0,50)
  95. LThrust=clamp(FlippedOff*((HoverThrust/cos(LPitch))+RollCounter+StrafeCounter),0,50)
  96. AThrust=clamp(FlippedOff*((HoverThrust/cos(APitch)*0-PitchCounter))+30*!FlippedOff,-40*!FlippedOff,40)
  97.  
  98. ###Counter Movement
  99.  
  100. ForwardVel=entity():velL():x()
  101. SideVel=entity():velL():y()
  102. AngVel=entity():angVel():yaw()
  103. SpeedCounter=(ForwardVel+$ForwardVel*1)*(1-Go)/10
  104. SpinCounter=(AngVel+$AngVel*5)/6
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement