Advertisement
Guest User

Untitled

a guest
Nov 18th, 2011
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.71 KB | None | 0 0
  1. local body = piece "body"
  2. local main = piece "main"
  3.  
  4. local head = piece "head"
  5. local pipesL = piece "pipesL"
  6. local pipesR = piece "pipesR"
  7.  
  8. local pistons = piece "pistons"
  9. local arms = piece "arms"
  10.  
  11. local platform = piece "platform"
  12. local turret = piece "turret"
  13. local guns = piece "guns"
  14. local flair1 = piece "flair1"
  15. local flair2 = piece "flair2"
  16.  
  17. local back = piece "back"
  18. local rocket1 = piece "rocket1"
  19. local rocket2 = piece "rocket2"
  20. local rocket3 = piece "rocket3"
  21. local rocket4 = piece "rocket4"
  22.  
  23. local armBR = piece "armBR"
  24. local wheelBR = piece "wheelBR"
  25. local trackBR1 = piece "trackBR1"
  26. local trackBR2 = piece "trackBR2"
  27. local BR = piece "BR"
  28.  
  29. local armFR = piece "armFR"
  30. local wheelFR = piece "wheelFR"
  31. local trackFR1 = piece "trackFR1"
  32. local trackFR2 = piece "trackFR2"
  33. local FR = piece "FR"
  34.  
  35. local armBL = piece "armBL"
  36. local wheelBL = piece "wheelBL"
  37. local trackBL1 = piece "trackBL1"
  38. local trackBL2 = piece "trackBL2"
  39. local BL = piece "BL"
  40.  
  41. local armFL = piece "armFL"
  42. local wheelFL = piece "wheelFL"
  43. local trackFL1 = piece "trackFL1"
  44. local trackFL2 = piece "trackFL2"
  45. local FL = piece "FL"
  46.  
  47. local SIG_MOVE = 1  --signal for the move animation thread
  48. local SIG_SUSP = 2  --signal for the suspension animation thread
  49.  
  50. local BRA = 0
  51. local FRA = 0
  52. local BLA = 0
  53. local FLA = 0
  54. local bodyA = 0
  55.  
  56. local function susp()
  57.  
  58.     Signal(SIG_SUSP)
  59.     SetSignalMask(SIG_SUSP)
  60.     while (true) do
  61.             --if ground_height_old == null then
  62.             --ground_height_old = 0
  63.             --end
  64.        
  65.         unitposx,unitposy,unitposz = Spring.GetUnitPosition(unitID)
  66.         ground_height = Spring.GetGroundHeight(unitposx,unitposz)
  67.         BRx,BRy,BRz = Spring.GetUnitPiecePosDir(unitID,BR)
  68.         BR_height = ground_height-(Spring.GetGroundHeight(BRx,BRz))
  69.         FRx,FRy,FRz = Spring.GetUnitPiecePosDir(unitID,FR)
  70.         FR_height = ground_height-(Spring.GetGroundHeight(FRx,FRz))
  71.         BLx,BLy,BLz = Spring.GetUnitPiecePosDir(unitID,BL)
  72.         BL_height = ground_height-(Spring.GetGroundHeight(BLx,BLz))
  73.         FLx,FLy,FLz = Spring.GetUnitPiecePosDir(unitID,FL)
  74.         FL_height = ground_height-(Spring.GetGroundHeight(FLx,FLz))
  75.        
  76.         --Spring.Echo (BR_height)
  77.         --Spring.Echo (FR_height)
  78.         --Spring.Echo (BL_height)
  79.         --Spring.Echo (FL_height)
  80.        
  81.        
  82.        
  83.         bodyLRHeight = ((BR_height+FR_height)/4)-((BL_height+FL_height)/4)
  84.        
  85.         Spring.Echo (bodyLRHeight)
  86.        
  87.         bodyTilt = math.asin(bodyLRHeight/25)
  88.        
  89.         Spring.Echo (bodyTilt)
  90.        
  91.         BRA = math.asin((BR_height-bodyLRHeight)/47)
  92.         FRA = math.asin((FR_height-bodyLRHeight)/47)
  93.         BLA = math.asin((BL_height+bodyLRHeight)/47)
  94.         FLA = math.asin((FL_height+bodyLRHeight)/47)
  95.  
  96.  
  97.  
  98.         bodyA = (FRA+FLA)/2
  99.      
  100.         Turn (main, 3, bodyTilt, math.rad(20))
  101.         Turn (platform, 3, -bodyTilt, math.rad(20))
  102.         Move (armBR, 2, -bodyLRHeight, 10)
  103.         Move (armFR, 2, -bodyLRHeight, 10)
  104.         Move (armBL, 2, bodyLRHeight, 10)
  105.         Move (armFL, 2, bodyLRHeight, 10)
  106.        
  107.         --height_dif = math.sqrt(math.abs(ground_height - ground_height_old) * 10)
  108.         --Spring.Echo (height_dif)
  109.         --Move (main, 2, -height_dif, 5)
  110.        
  111.         Turn (armBR, 1, -BRA, math.rad(20))
  112.         Turn (armFR, 1, FRA, math.rad(20))
  113.         Turn (armBL, 1, -BLA, math.rad(20))
  114.         Turn (armFL, 1, FLA, math.rad(20))
  115.         Turn (main, 1, bodyA, math.rad(20))
  116.         Turn (platform, 1, -bodyA)
  117.         Move (platform, 2, -bodyA*10)
  118.        
  119.         --ground_height_old = ground_height
  120.        
  121.         Sleep(40)
  122.     --Sleep(200)
  123.            
  124.     end
  125. end
  126.  
  127. function script.Create()
  128.     Show(trackFL1)
  129.         Show(trackFR1)
  130.         Show(trackBL1)
  131.         Show(trackBR1)
  132.     Hide(trackFL2)
  133.         Hide(trackFR2)
  134.         Hide(trackBL2)
  135.         Hide(trackBR2)
  136.         Turn (armBR, 1, 0)
  137.         Turn (armFR, 1, 0)
  138.         Turn (armBL, 1, 0)
  139.         Turn (armFL, 1, 0)
  140. end
  141.  
  142.  
  143. local function move()
  144.     Signal(SIG_MOVE)
  145.     SetSignalMask(SIG_MOVE)
  146.     while (true) do
  147.     Show(trackFL1)
  148.         Show(trackFR1)
  149.         Show(trackBL1)
  150.         Show(trackBR1)
  151.     Hide(trackFL2)
  152.         Hide(trackFR2)
  153.         Hide(trackBL2)
  154.         Hide(trackBR2)
  155.        
  156.         Sleep(70)
  157.        
  158.         Show(trackFL2)
  159.         Show(trackFR2)
  160.         Show(trackBL2)
  161.         Show(trackBR2)
  162.     Hide(trackFL1)
  163.         Hide(trackFR1)
  164.         Hide(trackBL1)
  165.         Hide(trackBR1)
  166.        
  167.         Sleep(70)
  168.    
  169.     end
  170. end
  171.  
  172.  
  173. function script.Killed()
  174.  
  175. end
  176.  
  177. local function open()
  178.     StartThread (move)
  179.     Turn (head, 1, -(math.rad(30)+bodyA), math.rad(40))
  180.     Turn (pipesL, 1, (math.rad(30)+bodyA), math.rad(40))
  181.     Turn (pipesR, 1, (math.rad(30)+bodyA), math.rad(40))
  182.     Turn (platform, 1, -(math.rad(30)+bodyA), math.rad(40))
  183.     Move (platform, 3, 7, 10)
  184.     Move (platform, 2, 2, 4)
  185.     Turn (main, 1, (math.rad(30)+bodyA), math.rad(40))
  186.     Turn (back, 1, -math.rad(50), math.rad(50))
  187.     Turn (pistons, 1, -math.rad(15), math.rad(15))
  188.     Move (arms, 3, -5, 5)
  189.     Move (arms, 2, 5, 5)
  190.     Move (body, 2, 12, 12)
  191.     Turn (armBR, 1, -(math.rad(20)+BRA), math.rad(20))
  192.     Turn (armFR, 1, (math.rad(20)+FRA), math.rad(20))
  193.     Turn (armBL, 1, -(math.rad(20)+BLA), math.rad(20))
  194.     Turn (armFL, 1, (math.rad(20)+FLA), math.rad(20))
  195.     Sleep(1000)
  196.     Signal(SIG_MOVE)
  197. end
  198.  
  199. local function close()
  200.     StartThread (move)
  201.     Turn (head, 1, 0, math.rad(40))
  202.     Turn (pipesL, 1, 0, math.rad(40))
  203.     Turn (pipesR, 1, 0, math.rad(40))
  204.     Turn (platform, 1, 0, math.rad(40))
  205.     Move (platform, 3, 0, 10)
  206.     Move (platform, 2, 0, 1)   
  207.     Turn (main, 1, bodyA, math.rad(30))
  208.     Turn (back, 1, 0, math.rad(50))
  209.     Turn (pistons, 1, 0, math.rad(15))
  210.     Move (arms, 3, 0, 5)
  211.     Move (arms, 2, 0, 5)
  212.     Move (body, 2, 0, 12)
  213.     Turn (armBR, 1, -BRA, math.rad(20))
  214.     Turn (armFR, 1, FRA, math.rad(20))
  215.     Turn (armBL, 1, -BLA, math.rad(20))
  216.     Turn (armFL, 1, FLA, math.rad(20))
  217.     Sleep(1000)
  218.     Signal(SIG_MOVE)
  219. end
  220.  
  221. function script.Activate()
  222.     StartThread (open)
  223.     return 1
  224. end
  225.  
  226. function script.Deactivate()
  227.     StartThread (close)
  228.     return 0
  229. end
  230.  
  231.  
  232.  
  233. function script.StartMoving()
  234.     StartThread (move)
  235.     StartThread (susp)
  236. end
  237.  
  238. function script.StopMoving()
  239.     Signal(SIG_MOVE)
  240.     Signal(SIG_SUSP)
  241. end
  242.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement