Advertisement
KrazziPro

Giant Spider Mech

Jun 25th, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.03 KB | None | 0 0
  1. @name Giant Spider Mech
  2. @persist [Legs Pos Ranger StepSeq Clk Dist Step Height Hit Hitnormal]:array
  3. @persist [E Pod]:entity
  4. @persist [Vel Rot Ang A1 Compensate RandomColor]:vector
  5. @persist [LegCount GC Runtime Anim Pos_comp Up_clamp Up_mul Interval Systime Rate H Leg_ground_hit_length Ranger_z_offset RangeDist Base_height]
  6. @persist [LR FB] Length1 Length2
  7. @persist LegDistance BaseHeight HI
  8. @persist SpinUp TRM BarrelSpin SpinRatio SpinLimit Mech:table
  9. @trigger
  10. @model models/hunter/blocks/cube025x025x025.mdl
  11.  
  12. interval(140)
  13. runOnLast(1)
  14.  
  15.  
  16. if(first()){
  17.  
  18.  
  19. HI = 100 #Starting index for the hologram body
  20.  
  21. SpinRatio = 3 #How fast the gatling spins up
  22. SpinLimit = 150 #RPM limit at which the gatling starts firing
  23. TRM = (tickInterval() > 0.03 ? 2 : 1)
  24.  
  25. E = entity() #Entity Spider self
  26. E:propGravity(0) #Make Spider Gravity Zero
  27. E:setMass(50000) #Set the Mass for the Spider
  28. E:setAlpha(0) #Set the cube (E2) invis
  29.  
  30. rangerFilter(Pod) #Filter the Seat from the ranger's
  31. rangerFilter(players()) #Filter Player's from the ranger's
  32.  
  33. Length1 = 55 #Length for the foot (upper)
  34. Length2 = 80 #Length for the foot (under)
  35.  
  36.  
  37. #The color of the accessories
  38. RandomColor = hsv2rgb(vec(20*(curtime())%360,0.8,0.8)) #Random Color
  39. #RandomColor = vec(106,8,136) #Solid Color
  40.  
  41. Interval = 1 #Animation rate (inverse to Rate for better performance. EG: Interval: 50, Rate 10; Interval: 100, Rate:5)
  42.  
  43. LegCount = 8
  44. LegDistance = 1 # Distance of the legs to the chip. Higher number means smaller distance
  45. Width = 30 #Foot Distance from the spider (Width)
  46. Length = 30 #Foot Distance from the spider (Lenght)
  47. Rate = 0.65 #SystemTime Rate
  48. Compensate = vec(3) #Ranger compensate
  49. Pos_comp = Length * 2 #Velocity compensation
  50.  
  51. Ranger_z_offset = 20 #Ranger offset (z)
  52. RangeDist = 210 #Ranger Distance
  53. BaseHeight = 75 #Ranger Height
  54. Leg_ground_hit_length = 150 #Leg Ground Hit Length
  55.  
  56. Up_mul = 1 #Leg cycle Z axis multiplier
  57. Up_clamp = 5 #Leg cycle Z axis clamp
  58.  
  59.  
  60.  
  61. function entity cUnits(Index:number,Posi:vector,Scale:vector,Angle:angle,Colo:vector,Model:string,Material:string,Parent:entity,Alpha:number,Shading:number){
  62. holoCreate(Index) holoPos(Index,Posi) holoScaleUnits(Index,Scale) holoAng(Index,Angle) holoColor(Index,Colo) holoModel(Index,Model) holoMaterial(Index,Material)
  63. holoParent(Index,Parent) holoAlpha(Index,Alpha) holoDisableShading(Index,Shading)
  64. return holoEntity(Index)
  65. }
  66.  
  67. cUnits(HI,E:toWorld(vec(0,0,0)),vec(60,60,18),E:toWorld(ang(0,-90,0)),vec(60),"hq_rcylinder","models/debug/debugwhite",E,255,1)
  68. HI += 1
  69.  
  70. cUnits(HI,E:toWorld(vec(-50,0,25)),vec(88,62,36),E:toWorld(ang(15,0,0)),vec(60),"hq_icosphere","models/debug/debugwhite",E,255,1)
  71. HI += 1
  72.  
  73. cUnits(HI,E:toWorld(vec(-50,0,31)),vec(88,62,48),E:toWorld(ang(15,0,0)),vec(60),"hq_icosphere","models/debug/debugwhite",E,255,1)
  74. HI += 1
  75.  
  76. cUnits(HI,E:toWorld(vec(-50,0,40)),vec(56,19,48),E:toWorld(ang(15,0,90)),RandomColor,"hq_rcylinder","models/debug/debugwhite",E,255,1)
  77. HI += 1
  78.  
  79. cUnits(HI,E:toWorld(vec(0,0,10)),vec(64,64,46),E:toWorld(ang(0,0,0)),vec(60),"hq_icosphere","models/debug/debugwhite",E,255,1)
  80. HI += 1
  81.  
  82. cUnits(HI,E:toWorld(vec(29.5,10,10)),vec(4,10,10),E:toWorld(ang(0,17,0)),vec(180,8,8),"hq_icosphere","models/debug/debugwhite",E,255,1)
  83. HI += 1
  84.  
  85. cUnits(HI,E:toWorld(vec(29.5,-10,10)),vec(4,10,10),E:toWorld(ang(0,-17,0)),vec(180,8,8),"hq_icosphere","models/debug/debugwhite",E,255,1)
  86. HI += 1
  87.  
  88. cUnits(HI,E:toWorld(vec(25,-18.5,10)),vec(4,10,10),E:toWorld(ang(0,-37,0)),vec(180,8,8),"hq_icosphere","models/debug/debugwhite",E,255,1)
  89. HI += 1
  90.  
  91. cUnits(HI,E:toWorld(vec(25,18.5,10)),vec(4,10,10),E:toWorld(ang(0,37,0)),vec(180,8,8),"hq_icosphere","models/debug/debugwhite",E,255,1)
  92. HI += 1
  93.  
  94. #####################
  95.  
  96.  
  97. for(I = 1, LegCount)
  98. {
  99. local Cos = cos((I / LegCount) * 360 + (180 / LegCount + 90)) * Width
  100. local Sin = sin((I / LegCount) * 360 + (180 / LegCount + 90)) * Length
  101.  
  102. Legs[I, entity] = holoCreate(I, E:toWorld(vec(Cos, Sin, 0)))
  103. Pos[I, vector] = vec(Cos, Sin, 0)
  104. Step[I, vector] = vec(Cos, Sin, 0)
  105. holoScale(I, vec())
  106. holoDisableShading(I,1)
  107.  
  108. #holoParent(I, E)
  109. }
  110.  
  111. StepSeq = array(
  112. 0, 1,
  113. 2, 3,
  114. 1, 2,
  115. 3, 4
  116. )
  117.  
  118. GC = StepSeq:count()
  119.  
  120. function setupPod(Vec:vector,Ang:angle,Parent:entity){
  121.  
  122. if(!Pod){
  123. findByClass("prop_vehicle_prisoner_pod")
  124. findSortByDistance(entity():pos())
  125.  
  126. if(find():owner()==owner()){
  127. Pod = find()
  128. Pod:setMass(0)
  129. }
  130.  
  131. }else{
  132.  
  133. if(!Pod:parent()){
  134.  
  135. if(Pod){
  136. Pod:setPos(Vec)
  137. Pod:setAng(Ang)
  138. if(!Pod:isFrozen()){
  139. Pod:propFreeze(1)
  140. }
  141. timer("load",1000)
  142. }
  143.  
  144. if(clk("load")){
  145. Pod:parentTo(Parent)
  146. Pod:setAlpha(0)
  147. DonePod = 1
  148. stoptimer("load")
  149. }
  150. }
  151. }
  152. }
  153.  
  154. function void entity:iK(Index, L1, L2, Targ:entity, Scale)
  155. {
  156. Holo = (Index * 1000) + 1
  157. if(first())
  158. {
  159. for(I = Holo, Holo + 2) #Increase the number with each hologram added to the legs
  160. {
  161. holoCreate(I)
  162. holoParent(I, I - 1)
  163. holoScale(I, vec(Scale))
  164. holoColor(I,vec(60, 60, 60))
  165. holoDisableShading(I,1)
  166. holoModel(I,"hq_sphere")
  167.  
  168. if(I > Holo)
  169. {
  170. holoClipEnabled(I, 1)
  171. }
  172. }
  173.  
  174. Knee = (Index * 2000)
  175. for(KneeHolo = Knee, Knee)
  176. {
  177. holoDisableShading(KneeHolo,1)
  178. holoCreate(KneeHolo)
  179. holoScale(KneeHolo, vec(0.51))
  180. holoModel(KneeHolo, "hq_sphere")
  181. holoColor(KneeHolo, RandomColor)
  182.  
  183. }
  184.  
  185. holoCreate(Holo + 3)
  186. holoCreate(Holo + 4)
  187. holoCreate(Holo + 5)
  188. holoPos(Knee, holoEntity(Holo+2):pos())
  189. holoParent(Knee, Holo+2)
  190. holoDisableShading(Knee,1)
  191.  
  192. holoParent(Holo, This)
  193. holoParent(Holo+4, Holo+1)
  194. holoParent(Holo+3, Holo+1)
  195. holoParent(Holo+5, Holo+2)
  196. holoDisableShading(Holo,1)
  197.  
  198. holoPos(Holo, This:toWorld(Pos[Index, vector] / LegDistance))
  199.  
  200. holoClip(Holo + 1, vec(), vec(0, 0, -1), 0)
  201. holoClip(Holo + 2, vec(), vec(0, 0, 1), 0)
  202. holoScale(Holo + 1, shiftR(vec(0.5, L1 / 6, 0.5))) # Hip to knee
  203. holoScale(Holo + 2, shiftR(vec(0.5, L2 / 6, 0.5))) # Knee to foot
  204. holoScale(Holo + 3, shiftR(vec(0.55, 1, 0.55))) # Hip to knee
  205. holoScale(Holo + 4, shiftR(vec(0.55, 0.5, 0.55))) # Hip to knee
  206. holoScale(Holo + 5, shiftR(vec(0.55, 0.5, 0.55))) # Hip to knee
  207.  
  208.  
  209. holoModel(Holo+1,"hq_cylinder")
  210. holoModel(Holo+2,"hq_sphere")
  211. holoModel(Holo+3,"hq_cylinder")
  212. holoModel(Holo+4,"hq_cylinder")
  213. holoModel(Holo+5,"hq_cylinder")
  214.  
  215. holoColor(Holo+3,RandomColor)
  216. holoDisableShading(Holo+3,1)
  217. holoColor(Holo+4,RandomColor)
  218. holoDisableShading(Holo+4,1)
  219. holoColor(Holo+5,RandomColor)
  220. holoDisableShading(Holo+5,1)
  221.  
  222.  
  223. holoPos(Holo + 1, holoEntity(Holo):pos())
  224. holoPos(Holo + 2, holoEntity(Holo + 1):toWorld(vec(0, 0, -L1)))
  225. holoPos(Holo + 3, holoEntity(Holo):pos()-vec(0,0,10))
  226. holoPos(Holo + 4, holoEntity(Holo):pos()-vec(0,0,40))
  227. holoPos(Holo + 5, holoEntity(Holo):pos()-vec(0,0,20))
  228. }
  229.  
  230.  
  231. local Rotation = ang(0, 0, 0)
  232.  
  233. local Dir = Targ:pos() - holoEntity(Holo):pos()
  234. local AxisA = E:toLocalAxis(Dir):rotate(Rotation)
  235. local AxisB = holoEntity(Holo):toLocalAxis(Dir)
  236. local LegCount = min(Dir:length(), L1 + L2)
  237.  
  238. local Hip_p = atan(-AxisB[3], AxisB[1]) + acos((LegCount^2 + L1^2 - L2^2) / (2 * L1 * LegCount)) - 90
  239. local Knee = acos((L1^2 + L2^2 - LegCount^2) / (2*L1*L2))
  240.  
  241. holoAng(Holo, This:toWorld(ang(0, atan(AxisA[2], AxisA[1]) + 180, 0) - Rotation))
  242. holoAng(Holo + 1, holoEntity(Holo):toWorld(ang(Hip_p, 0, 0)))
  243. holoAng(Holo + 2, holoEntity(Holo + 1):toWorld(ang(Knee, 0, 0)))
  244. }
  245.  
  246. Systime = Rate / LegCount
  247.  
  248. rangerPersist(1)
  249. Const = E:getConstraints()
  250. Const:pushEntity(Pod)
  251. rangerFilter(Const)
  252. rangerFilter(players())
  253.  
  254. interval(Interval)
  255.  
  256.  
  257. function walking(){
  258.  
  259. Vel = E:velL():setZ(E:velL():z() / 10)
  260. Rot = E:angVelVector()
  261.  
  262. Driver = Pod:driver()
  263. W = Driver:keyForward()
  264. S = Driver:keyBack()
  265. A = Driver:keyLeft()
  266. D = Driver:keyRight()
  267. Space = Driver:keyJump()
  268. Shift = Pod:driver():keySprint()
  269. Alt = Driver:keyWalk()
  270. ALT = Driver:keyPressed("LALT")
  271.  
  272. Systime += (Rate * (1 + Shift / 2))+ (abs(Rot:z() / 600))
  273. Systime = Systime % (GC / 2)
  274.  
  275. Base_height = BaseHeight - (ALT*25)
  276.  
  277. for(I = 1, LegCount){
  278. local LG = ((I * 2) - 1) % GC ? ((I * 2) - 1) % GC : GC
  279. local HG = (I * 2) % GC ? (I * 2) % GC : GC
  280.  
  281. local High = StepSeq[I * 2 % GC, number]
  282. local Low = StepSeq[(I * 2 - 1) % GC, number]
  283.  
  284. local HH = High % (GC / 2)
  285. local LL = Low % (GC / 2)
  286.  
  287. local Range = inrange(Systime, clamp(Low, 0, Low), High) | inrange(Systime, LL, LL * 2 - HH) | inrange(Systime, HH * 2 - LL, HH)
  288.  
  289. local Sin = sin((I / LegCount) * 360 + (180 / LegCount + 90)) / 2
  290. local Cos = cos((I / LegCount) * 360 + (180 / LegCount + 90)) / 2
  291.  
  292. local HoverRan = rangerOffset(1000,E:toWorld(vec(0,0,0)),E:up()*-1)
  293.  
  294. E:iK(I, Length1, Length2, Legs[I, entity], 0.5)
  295.  
  296.  
  297. Ranger[I, ranger] = rangerOffset(RangeDist, E:toWorld(Pos[I, vector] + vec(0, 0, Ranger_z_offset) + clamp((Vel:setZ(0) / Compensate), -vec(Pos_comp), vec(Pos_comp))), vec(Cos, Sin, -1):rotate(E:toWorld(ang(0, 0, 0))))
  298.  
  299. if(Ranger[I, ranger]:distance() >= Leg_ground_hit_length)
  300. {
  301. Ranger[I, ranger] = rangerOffset(RangeDist, E:toWorld(Pos[I, vector] * (10 / 2) + vec(0, 0, Ranger_z_offset)), vec(-Cos, -Sin, -1):rotate(E:toWorld(ang(0, 0, 0))))
  302. }
  303.  
  304.  
  305.  
  306. if(!Legs[I, entity])
  307. {
  308. Legs[I, entity] = holoCreate(I, Ranger[I, ranger]:pos(), vec())
  309. holoParent(I, E)
  310. hint(Legs[I, entity]:toString(), 10)
  311. }
  312.  
  313. if(Ranger[I, ranger]:distance() <= Leg_ground_hit_length)
  314. {
  315. if(Clk[I, number] != Range)
  316. {
  317. Clk[I, number] = Range
  318. if(Range)
  319. {
  320. Step[I, vector] = Ranger[I, ranger]:position()
  321. Dist[I, number] = abs(holoEntity(I):pos():distance(Ranger[I, ranger]:position()))
  322. if(Ranger[I, ranger]:entity())
  323. {
  324. holoParent(I, Ranger[I, ranger]:entity())
  325. } else {
  326. holoUnparent(I)
  327. }
  328. } else {
  329. if(Dist[I, number] > 10)
  330. {
  331. holoPos(I, Step[I, vector])
  332. holoEntity(I):soundPlay(100 + I, 0.368, "npc/stalker/stalker_footstep_left"+randint(1,2)+".wav") #npc/stalker/stalker_footstep_left"+randint(1,2)+".wav
  333. soundPitch(100 + I, 100)
  334. }
  335. Hitnormal[I, vector] = Ranger[I, ranger]:hitNormal():rotate(ang(0, -E:angles():yaw() + 90, 0))
  336. }
  337. }
  338.  
  339. if(Clk[I, number] & Dist[I, number] > 10)
  340. {
  341. local Di = clamp(Dist[I, number] * Up_mul, 0, Up_clamp) #Get step distance
  342. local Dur = StepSeq[HG, number] - StepSeq[LG, number] #Get duration of step
  343. local Calc = 1 / Dur #Convert to dividend of 1 (for time)
  344. local Seq = Systime % Dur #Find remainder (for step duration). Multiplied by Calc to ensure 0 to 1 sequencing.
  345. local Mix = mix(mix(Step[I, vector], holoEntity(I):pos() + E:up() * Di, Seq), mix(holoEntity(I):pos() + E:up() * Di, holoEntity(I):pos(), Seq), Seq)
  346.  
  347. holoPos(I, Mix)
  348. }
  349. } else {
  350. holoPos(I, Ranger[I, ranger]:position())
  351. Step[I, vector] = Ranger[I, ranger]:position()
  352. }
  353.  
  354. Height[I, number] = Ranger[I, ranger]:distance()
  355. }
  356.  
  357. LR = FB = 0
  358. Angles = E:angles()
  359. A1 = vec()
  360.  
  361. for(I = 1, Step:count())
  362. {
  363. A1 += holoEntity(I):pos()
  364.  
  365. local Cos = cos((I / LegCount) * 360 + (180 / LegCount + 90))
  366. local Sin = sin((I / LegCount) * 360 + (180 / LegCount + 90))
  367. LR += Height[I, number] * Cos
  368. FB += Height[I, number] * Sin
  369. }
  370. A1 /= LegCount
  371.  
  372.  
  373. Ang = clamp(vec(-FB, LR, 0), -100, 100)
  374.  
  375.  
  376. local Ground = (Height:min() <= Leg_ground_hit_length)
  377.  
  378. local H = (((A1 + (E:up() * Base_height) - E:pos()) * !Space * Ground) - vec(0, 0, 20 * !Ground))
  379. local Res = (E:vel() * vec(0.8) * !Space * Ground * E:mass())
  380.  
  381. local Move = ((-E:forward() * (W - S)) * (30 * (1 + Shift)) * Ground * E:mass() * 4)
  382. local Jump = E:up() * Space * 300 * Ground * E:mass()
  383.  
  384. local Turn = vec(0, 0, ((A - D))) * 600 * Ground * E:inertia() * 2
  385.  
  386. E:applyForce((H * E:mass() * vec(2, 2, 4)) - Res - Move + Jump)
  387. E:applyTorque((Ang * E:inertia() * (100 / (2 * 1.5))) - (E:angVelVector() * E:inertia() * (20 + (5))) + Turn * (2))
  388. }
  389.  
  390.  
  391. function runE2(){
  392.  
  393. walking()
  394. setupPod(E:toWorld(vec(-12,0,24)),E:toWorld(ang(0,-90,0)),E)
  395.  
  396. }
  397.  
  398. }
  399.  
  400.  
  401. if(last()){ Pod:propDelete() }
  402.  
  403.  
  404. if(opcounter()<(softQuota()) & perf()){
  405. runE2()
  406. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement