hwarren

Hover Chip

May 29th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.29 KB | None | 0 0
  1. @name Hover Controls
  2. @inputs Pod:entity
  3. @outputs
  4. @persist [E Base]:entity Speed Hoverheight Turnspeed Mass Drift T Bobspeed Bobdistance
  5. @persist [Move Ambient Turn On Off]:string
  6. interval(130)
  7.  
  8. if(first()) {
  9. ##You might need to change these
  10.     ##Movement
  11.     Speed = 130       #How fast the vehicle moves
  12.     Turnspeed = 75   #How fast the vehicle turns
  13.     Hoverheight = 50 #How high the vehicle hovers
  14.     Drift = 1        #Higher = more drift        note: be careful with this
  15.     Bobspeed = 1     #How fast the vehicle "bounces" while idle
  16.     Bobdistance = 5  #How much the vehicle "bounces" while idle
  17.    
  18.     ##Sounds - not all sounds will fit with a vehicle
  19.     Move = "thrusters/hover02.wav"
  20.     soundPlay("move", 0, Move)
  21.    
  22.     Ambient = "npc/combine_gunship/dropship_engine_distant_loop1.wav"
  23.     soundPlay("ambient", 0, Ambient)
  24.    
  25.     Turn = "thrusters/rocket00.wav"
  26.     soundPlay("turn", 0, Turn)
  27.    
  28.     On = "hl1/fvox/activated.wav"
  29.     soundPitch("on", 75)
  30.    
  31.     Off = "ambient/energy/powerdown2.wav"
  32.     soundPitch("off", 100)
  33.    
  34.    
  35. ##You shouldn't need to change these
  36.    
  37.    E = entity()
  38.    
  39.    Base = E:isWeldedTo()
  40.    Base:setMass(30000)
  41.    
  42.    Props = E:getConstraints()
  43.    
  44.    for(I = 1, Props:count()) {
  45.        Mass = Mass + Props[I, entity]:mass()
  46.        Props[I, entity]:propGravity(0)
  47.    }
  48.  
  49.            if(Base) {
  50.                print("----------------------------------------------------------------------")
  51.                print("> Remember that you can change settings in the editor")
  52.                print("> The vehicle will rotate around the base prop")
  53.                print("> To avoid problems, build everything facing foward (in relation to the world)")
  54.                print("     > You need to rotate " + round(Base:forward():dot(vec(1,0,0))*90+90) + " degrees")
  55.                print("> Be sure to keep under the base prop clear")
  56.                hint("Mass = " + Mass, 5)
  57.                
  58.            } else {
  59.                print("> No base found - spawn the E2 on a prop")  
  60.                selfDestruct()
  61.            }
  62.  
  63. }
  64.  
  65. T = T + Bobspeed
  66.  
  67. Dri = Pod:driver()
  68. W = Dri:keyForward()
  69. A = Dri:keyLeft()
  70. S = Dri:keyBack()
  71. D = Dri:keyRight()
  72. Shift = Dri:keySprint()
  73.  
  74. rangerFilter(array(Base))
  75. rangerHitWater(1)
  76. R = rangerOffset(Hoverheight*3, Base:toWorld(vec(0,0,-5)), vec(0,0,-1))
  77. rangerFilter(array(Base))
  78. rangerHitWater(1)
  79. R2 = rangerOffset(Hoverheight*3, E:toWorld(vec(50,0,-5)), vec(0,0,-1))
  80.  
  81. Z = R:hit() ? (Hoverheight-R:distance())/(0.33*Drift) + sin(T*10)*Bobdistance : -250
  82. Base:applyForce((-Base:vel()/(2*Drift) + E:forward()*(W-S)*Speed*(Shift+1) + vec(0,0,Z))*Mass)
  83.  
  84. Pitch = R:hit() ? ((R2:pos()/2):z() - (R:pos()/2):z()) : 0
  85.  
  86. Base:applyAngForce((-Base:angVel()/(0.33*Drift) + ang(Pitch-Base:angles():pitch(),(A-D)*Turnspeed,0-Base:angles():roll())*2)*Mass)
  87.  
  88.    soundPitch("ambient", Dri ? 75 : 0)
  89.  
  90. soundPitch("move", 0+abs(Base:vel():length()/13))
  91. soundPitch("turn", 0+abs(Base:angVel():yaw()/3))
  92.  
  93.  
  94. if(changed(Dri)) {
  95.    if(Dri) {
  96.        soundPlay("on", 1, On)
  97.        soundPitch("on", 85)
  98.        
  99.        soundPlay("ambient", 0, Ambient)
  100.    }
  101.    
  102.    if(!Dri) {
  103.        soundPlay("off", 1, Off)
  104.        soundPitch("off", 100)
  105.        
  106.        soundPitch("ambient", 0)
  107.    }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment