Jump to content




Sensor turtle moving to player location


  • You cannot reply to this topic
1 reply to this topic

#1 tvc

  • Members
  • 35 posts

Posted 15 July 2013 - 07: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

#2 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 16 July 2013 - 11:09 AM

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users