dcchill

helm

Apr 23rd, 2023 (edited)
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. local reader = peripheral.find("ship_reader")
  2. local helm = peripheral.find("ship_helm")
  3.  
  4.  
  5. angle = 0
  6.  
  7. local x1 = 0
  8. local z1 = 0
  9.  
  10. print('x')
  11. local x1 = tonumber(io.read())
  12. print('z')
  13. local z1 = tonumber(io.read())
  14.  
  15.  
  16. while true do
  17. sleep(0.02)
  18.  
  19. local pos = reader.getWorldspacePosition()
  20. local der = reader.getRotation()
  21.  
  22. local x = pos['x']
  23. local z = pos['z']
  24.  
  25. local der = der['roll'] * 57.2957795 + 180
  26.  
  27. local xdif = x1 - x
  28. local zdif = z1 - z
  29.  
  30.  
  31.  
  32. if z1 > z then
  33. angle = math.asin(xdif/math.sqrt(zdif^2 + xdif^2)) * 57.2957795 +90
  34. elseif z1 < z and x1 > x then
  35. if zdif < 0 then zdif = zdif *-1 end
  36. angle = math.asin(zdif/math.sqrt(zdif^2 + xdif^2)) * 57.2957795 +180
  37. elseif z1 < z and x1 < x then
  38. if xdif > 0 then xdif = xdif *-1 end
  39. if zdif > 0 then zdif = zdif *-1 end
  40. angle = math.asin(zdif/math.sqrt(zdif^2 + xdif^2)) * 57.2957795
  41.  
  42. end
  43.  
  44. if angle < 0 then
  45. angle = 360 + angle
  46. elseif angle > 360 then
  47. angle = angle - 360
  48. end
  49.  
  50.  
  51.  
  52. if der > angle and der < angle + 180 then
  53. helm.move('left', false)
  54. helm.move('right', true)
  55. print('right')
  56.  
  57. elseif der > angle + 180 or der < angle then
  58. helm.move('right', false)
  59. helm.move('left', true)
  60. print('left')
  61. end
  62.  
  63.  
  64. if der > angle - 20 and der < angle + 20 then
  65. helm.move('forward', true)
  66. else
  67. helm.move('forward', false)
  68. end
  69.  
  70. print(der, angle)
  71.  
  72. end
Advertisement
Add Comment
Please, Sign In to add comment