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

How would I make my placement system go infront of where my mouse is?

Asked by 3 years ago

Hi, so I am currently creating a Minecraft-type building system. However, I would like to add a specific feature where if my mouse target is nil, it'll place it on the next best place. Do have in mind this is a minecraft type building. So if i'm high up in the sky and my mouse is in the sky forward, but not on the block it'll place a block 3 studs ahead of where it currently is. Here is the code to support my question!

Mouse.Move:Connect(function()
    if Mouse.Target and Equipped and Mouse.Target.Name == BlockName then
        if Mouse.TargetSurface == Enum.NormalId.Top then
            SelectionBlock.CFrame = Mouse.Target.CFrame * CFrame.new(0,height,0)
        end
        if Mouse.TargetSurface == Enum.NormalId.Bottom then
            SelectionBlock.CFrame = Mouse.Target.CFrame * CFrame.new(0,-height,0)
        end

        if Mouse.TargetSurface == Enum.NormalId.Left then
            SelectionBlock.CFrame = Mouse.Target.CFrame * CFrame.new(-height,0,0)
        end
        if Mouse.TargetSurface == Enum.NormalId.Right then
            SelectionBlock.CFrame = Mouse.Target.CFrame * CFrame.new(height,0,0)
        end
    end
    if Mouse.Target == nil or Mouse.Target.Name ~= BlockName then

        local poes = CFrame.new(Mouse.Hit.Position):PointToObjectSpace(Mouse.Origin.Position)
        local poesx = Round(poes.X,3) -- size of the blocks 3x3x3
        local poesz = Round(poes.Z,3) -- size of the blocks 3x3x3
        if poesx and poesz then
            this is where it'll go ahead
        else
            this is where its in a random position and it wont highlight
        end


    end
end)

Any help in doing this would be a huge help !

Answer this question