This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
tvc's profile picture

Sensor turtle moving to player location

Started by tvc, 15 July 2013 - 06:59 PM
tvc #1
Posted 15 July 2013 - 08:59 PM
so i have having an issue with getting a sensor turtle to move to a players location


what i have so far also someone tell me how to use the spoiler button would be great.


os.loadAPI("ocs/apis/sensor")

prox = sensor.wrap("right")

while true do

for target in pairs(prox.getTargets())
local details = prox.getTargetDetails(target)
if details.Name == "Player" then
playerPos = details.Position
x = playerPos["X"]
Z = playerPos["Z"]



and thats as far as i can get for two reason

1) the locations are grid line based so numbers are never whole
2) if the turtle turns around i have to make sure he will still go the same way

so i can not use if x < 0 turtle.back() because if i turn the turtle to the left that is no longer true


main goal turtle will fly over a player and drop an anvil
Bubba #2
Posted 16 July 2013 - 12:09 PM
Well, it actually is true because the coordinates that the turtle senses do not change based on the turtle's rotation. Only when the player or turtle moves along an axis do the coordinates change.

As for the whole numbers issue - simply use math.floor(n) and math.ceil(n) in order to achieve rounding.

I myself have actually done this before, and as such I know that for some odd reason, it's best if you use math.ceil for the x-coord and math.floor for the other two. Otherwise the turtle is always one off.