Finding exact positions of blocks when player is moving quickly

Started by SpencerWhite, Mar 31, 2019, 08:53 PM

Previous topic - Next topic

SpencerWhite

Hi there, I'm making a turtle swarm that will use a neural interface to scan for blocks and send those positions out to turtles. I'm getting stuck on the scanning part because, whenever the player moves really quickly, the position of the block changes. For example, if I have a single gold ore near me, it will get the position of the gold ore correct, but if I jump up and down, it will stop working.

local function scan()
    while true do
        rawLocation = {gps.locate()}
        roundedLocation = {
            ["x"] = math.floor(rawLocation[1]),
            ["y"] = math.floor(rawLocation[2]),
            ["z"] = math.floor(rawLocation[3]),
        }
        for _, block in pairs(modules.scan()) do
            if lookingFor[block.name] == 1 then
                --print(block.name .. " at " .. block.x+roundedLocation.x .. "," .. block.y+roundedLocation.y .. "," .. block.z+roundedLocation.z)
                blockQueue[block.x+roundedLocation.x .. "," .. block.y+roundedLocation.y .. "," .. block.z+roundedLocation.z] = block.name
            end
        end
        os.sleep(settings.blockFinderInterval)
    end
end

My best guess is that it has to do with how the player's current position is rounded. It's also difficult because I'm not sure exactly how the block scanner rounds the relative locations of blocks either. I've seen this done before, so I know that it's possible, but I'm really struggling with it. Any help would be very much appreciated!

Dog

I don't know anything about the neural interface, but I did notice that you have a sleep in your posted code.  While a sleep is being carried out all other events received are discarded - that *might* be part of the problem.  Without the sleep, however, it looks to me like the code will generate a failure to yield error.  You could change the os.sleep(settings.blockFinderInterval) to os.sleep(0) and see if that helps - that'll give you the shortest sleep possible and avoid failure to yield errors.

SpencerWhite

Hey, thanks for the reply. I'm on a server right now and the sleep is there so that not too many server resources are used up (in this case, it only runs the scan code every 0.2 seconds because of how large the table is). The main issue is that, when I'm jumping and moving around, the position of the ore keeps changing around because of how things are rounded.

The scanner returns a position relative to the neural interface. The only issue with this is that this item is worn on a player, so it's really difficult to get an exact world position.

SpencerWhite

Hey, I figured out the issue. It turns out, if you're on the very edge of a block, a gps.locate rounding issue will return you being on the wrong block, but the block scanner will still return the correct block. I think I'll just need to make my own gps program.

Dog

Glad to hear you figured it out.  Good luck with your GPS program!