Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the difference between these two mouse properties?

Asked by 8 years ago

I've read the description on the wiki of the Mouse.Hit Property and I understand it perfectly.

However, after reading the description of the Origin I didn't quite understand what it was saying.

I created this code as an attempt to understand it but I still didn't get it.

script.Parent.Equipped:connect(function(M)
    M.Move:connect(function()
        print(M.Origin.X)
        print(M.Hit.X)
        wait(5)
    end)
end)

This is inside a local script within a tool.

My overall intent is to create a BASIC dropper tool that only works over a given base. This is what I have so far.

--Sets up the array for taken spaces
avaliableSpaces = {}
for avSet=0,15 do
    avaliableSpaces[avSet] = {}
end

--Sets all values on the board to zero
for row=0,14 do
    for column=0,14 do
        avaliableSpaces[row][column] = 0
    end
end

--Used to check and see if a space is taken
function checkAvaliablity(x,z)
    --Gets area code for x and z values
    x = math.floor((x + 30)/4)
    z = math.floor((z + 30)/4)
    if(avaliableSpaces[x][z] == 0) then
        return true
    end
    return false
end

script.Parent.Equipped:connect(function(M)
    --Creating the invisible brick 
    xy = Instance.new("Part", game.Workspace)
    xy.Size = Vector3.new(4,4,4)
    xy.Anchored = true
    xy.CanCollide = false
    xy.Transparency = 0.5
    xy.Name = game.Players.LocalPlayer.Name.."Brick"
    xy.CFrame = game.Workspace.Base.CFrame:toWorldSpace(CFrame.new(0,2.5,0))
    yx = Instance.new("SelectionBox",xy)
    yx.Adornee = xy
    yx.Color = BrickColor.new("Dark stone grey")

    M.Move:connect(function()
        if M.Target == game.Workspace.Base then
            --Now we need to find the x coordinates
            xValue = game.Workspace.Base.CFrame:toObjectSpace(M.Hit).X
            local xRoundValue = xValue%4
            if xRoundValue == 3 or xRoundValue == 2 then
                xValue = math.ceil(xValue/4)*4
            else
                xValue = math.floor(xValue/4)*4
            end

            --We also need to find our z coodinates
            zValue = game.Workspace.Base.CFrame:toObjectSpace(M.Hit).Z
            local zRoundValue = zValue%4
            if zRoundValue == 3 or zRoundValue == 2 then
                zValue = math.ceil(zValue/4)*4
            else
                zValue = math.floor(zValue/4)*4
            end

            --Now it is time to actually move the brick
            if checkAvaliablity(xValue,zValue) then
                xy.CFrame = game.Workspace.Base.CFrame:toWorldSpace(CFrame.new(xValue,2.5,zValue))--2.5 will never change as long as the base and brick is the same
            end
        end
    end)

    --This actually creates the brick
    M.Button1Down:connect(function()
        --Put the brick down
        local brk = Instance.new("Part", game.Workspace)
        brk.Size = Vector3.new(4,4,4)
        brk.Anchored = true
        brk.CFrame = xy.CFrame

        --Lock the space
        local x = math.floor((xValue + 30)/4)
        local z = math.floor((zValue + 30)/4)
        avaliableSpaces[x][z] = 1

        --Move the invisible brick away
        xy.CFrame = CFrame.new(0,0,0)
    end)
end)

--Destory the brick when the tool is unequipped
script.Parent.Unequipped:connect(function()
    game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name.."Brick"):Destroy()
end)

It doesn't work for anything except one level above the base. It isn't stackable yet. Currently it decides if a space is open by checking a preset database at the top. I don't like this but I haven't found a way around it yet.

It moves in a 4x4 grid. The base is a 60x60 stud brick.

I am open to any suggestions.

0
mouse.Hit is the place the mouse hits in workspace. mouse.Origin is the player's camera cframe, pointed at that position. You can do the same with CFrame.new(workspace.CurrentCamera.CFrame.p,mouse.Hit.p). It's really specific and I don't know when it would be useful. cabbler 1942 — 8y

Answer this question