Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- modules = peripheral.wrap("back")
- function main()
- modules.disableAI()
- while true do
- player = modules.getMetaByName("mikesc")
- if player ~= nil then
- local x = player.x
- local y = player.y
- local z = player.z
- local pitch = -math.atan2(y, math.sqrt(x * x + z * z))
- local yaw = math.atan2(-x, z)
- local distancetoplayer = distance(0,0,x,z)
- if not modules.isWalking()
- if distancetoplayer > 6 then
- local newx = -(distancetoplayer - 2) * math.sin(yaw) * math.cos(pitch)
- --local newy = (distancetoplayer - 2) * math.sin(yaw) * math.sin(pitch)
- local newz = (distancetoplayer - 2) * math.cos(yaw)
- success = modules.walk(newx,y,newz)
- if not success then
- modules.walk(x,y,z)
- end
- else
- modules.look(math.deg(yaw), math.deg(pitch))
- end
- end
- end
- os.sleep(2)
- end
- end
- function distance ( x1, y1, x2, y2 )
- local dx = x1 - x2
- local dy = y1 - y2
- return math.sqrt ( dx * dx + dy * dy )
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement