Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --setup
- local reader = peripheral.find("ship_reader")
- local helm = peripheral.find("ship_helm")
- function sign(number)
- return number > 0 and 1 or (number == 0 and 0 or -1)
- end
- function getYaw()
- rot = reader.getRotation(true)
- shipYaw = math.atan2(2*rot.y*rot.w-2*rot.x*rot.z,1-2*rot.y*rot.y-2*rot.z*rot.z )
- return shipYaw
- end
- local detector = peripheral.find("playerDetector")
- helm.move("forward",true)
- --loop start
- while true do
- --get player position
- local player = detector.getPlayerPos("3F0x")
- --get ship position
- local shipPosition = reader.getWorldspacePosition()
- --get ship rotation
- local shipRot = reader.getRotation()
- --get current yaw direction
- local shipYaw = getYaw()*(180/3.14159)
- if sign(shipYaw) == -1 then
- shipYaw = 360 + shipYaw
- end
- --get ideal yaw direction
- local idealYaw = 360
- local idealYawX = 360
- local idealYawz = 360
- if shipPosition.x < player.x then
- idealYawX = 160
- elseif shipPosition.x > player.x then
- idealYawX = 340
- end
- if shipPosition.z < player.z then
- idealYawZ = 70
- elseif shipPosition.z > player.z then
- idealYawZ = 250
- end
- idealYaw = (idealYawX + idealYawZ) / 2
- if idealYawX == 340 and idealYawZ == 70 then
- idealYaw = 25
- end
- print("ideal: "..idealYaw.. " idealX: "..idealYawX.. "idealz: ".. idealYawZ )
- local d1 = "left"
- local d2 = "right"
- if shipYaw < idealYaw then
- helm.move(d1,true)
- else
- helm.move(d2 ,true)
- end
- print("Yaw ".. shipYaw )
- -- helm.move("left",true)
- end
Advertisement
Add Comment
Please, Sign In to add comment