Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local reader = peripheral.find("ship_reader")
- local helm = peripheral.find("ship_helm")
- angle = 0
- local x1 = 0
- local z1 = 0
- print('x')
- local x1 = tonumber(io.read())
- print('z')
- local z1 = tonumber(io.read())
- while true do
- sleep(0.02)
- local pos = reader.getWorldspacePosition()
- local der = reader.getRotation()
- local x = pos['x']
- local z = pos['z']
- local der = der['roll'] * 57.2957795 + 180
- local xdif = x1 - x
- local zdif = z1 - z
- if z1 > z then
- angle = math.asin(xdif/math.sqrt(zdif^2 + xdif^2)) * 57.2957795 +90
- elseif z1 < z and x1 > x then
- if zdif < 0 then zdif = zdif *-1 end
- angle = math.asin(zdif/math.sqrt(zdif^2 + xdif^2)) * 57.2957795 +180
- elseif z1 < z and x1 < x then
- if xdif > 0 then xdif = xdif *-1 end
- if zdif > 0 then zdif = zdif *-1 end
- angle = math.asin(zdif/math.sqrt(zdif^2 + xdif^2)) * 57.2957795
- end
- if angle < 0 then
- angle = 360 + angle
- elseif angle > 360 then
- angle = angle - 360
- end
- if der > angle and der < angle + 180 then
- helm.move('left', false)
- helm.move('right', true)
- print('right')
- elseif der > angle + 180 or der < angle then
- helm.move('right', false)
- helm.move('left', true)
- print('left')
- end
- if der > angle - 20 and der < angle + 20 then
- helm.move('forward', true)
- else
- helm.move('forward', false)
- end
- print(der, angle)
- end
Advertisement
Add Comment
Please, Sign In to add comment