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

Placement System Collision Problems?

Asked by 2 years ago
Edited 2 years ago

Here is a video of my problem,

Youtube Video

At the start of the video you can see what I am trying to achieve but then when I tilt the block it just doesn't want to work. I know why it isn't working but I can't really think of a way to fix it?

Here is my current code,

local Player = game.Players.LocalPlayer
local workspace = game.Workspace
local rot = 90
local plot = game.Workspace.plot
local gsize = 0.5

local UserInputService = game:GetService("UserInputService")
local Mouse = Player:GetMouse()
Mouse.TargetFilter = game.Workspace:FindFirstChild(Player)
local RunService = game:GetService("RunService")


local DummyBlock = game.ReplicatedStorage.Block:Clone(); DummyBlock.CFrame = CFrame.new(0,0,0); DummyBlock.Parent = workspace; DummyBlock.Name = "DummyBlock"; DummyBlock.Transparency = 0.5; DummyBlock.CanCollide = false; DummyBlock.Anchored = true;DummyBlock.Color = Color3.fromRGB(0, 68, 216)
Mouse.TargetFilter = DummyBlock
local function roundToStep(initialValue,step)
    local roundedValue = math.floor(initialValue/step)*step
    return roundedValue
end

RunService.RenderStepped:Connect(function()
    if Mouse.TargetSurface == Enum.NormalId.Right then
        DummyBlock.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, gsize)+DummyBlock.Size.X/2, roundToStep(Mouse.Hit.Position.Y, gsize)+DummyBlock.Size.Y/2, roundToStep(Mouse.Hit.Position.Z, gsize))
    elseif Mouse.TargetSurface == Enum.NormalId.Left then
        DummyBlock.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, gsize)-DummyBlock.Size.X/2, roundToStep(Mouse.Hit.Position.Y, gsize)+DummyBlock.Size.Y/2, roundToStep(Mouse.Hit.Position.Z, gsize))
    elseif Mouse.TargetSurface == Enum.NormalId.Front then
        DummyBlock.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, gsize), roundToStep(Mouse.Hit.Position.Y, gsize)+DummyBlock.Size.Y/2, roundToStep(Mouse.Hit.Position.Z, gsize)-DummyBlock.Size.Z/2)
    elseif Mouse.TargetSurface == Enum.NormalId.Back then
        DummyBlock.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, gsize), roundToStep(Mouse.Hit.Position.Y, gsize)+DummyBlock.Size.Y/2, roundToStep(Mouse.Hit.Position.Z, gsize)+DummyBlock.Size.Z/2)
    else
        DummyBlock.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, gsize), roundToStep(Mouse.Hit.Position.Y, gsize)+DummyBlock.Size.Y/2, roundToStep(Mouse.Hit.Position.Z, gsize))
    end
    wait(0.01)
end)

UserInputService.InputBegan:Connect(function(keycode)
    if keycode.KeyCode == Enum.KeyCode.E then
        local look = Mouse.Target.CFrame.LookVector.X
        local colorV = script.Parent.Parent.Color.Value
        local result = game.Workspace:Raycast(DummyBlock.Position,Vector3.new(0,-10,0))
        local Block = game.ReplicatedStorage.Block:Clone(); Block.Parent = workspace.plotItems; Block.Anchored = true;Block.BrickColor = BrickColor.new(colorV)
        Block.Orientation = DummyBlock.Orientation
        if result.Instance == game.Workspace.plot or result.Instance.Name == "Block" then
            if Mouse.TargetSurface == Enum.NormalId.Right then
                Block.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, gsize)+DummyBlock.Size.X/2, roundToStep(Mouse.Hit.Position.Y, gsize)+DummyBlock.Size.Y/2, roundToStep(Mouse.Hit.Position.Z, gsize))
            elseif Mouse.TargetSurface == Enum.NormalId.Left then
                Block.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, gsize)-DummyBlock.Size.X/2, roundToStep(Mouse.Hit.Position.Y, gsize)+DummyBlock.Size.Y/2, roundToStep(Mouse.Hit.Position.Z, gsize))
            elseif Mouse.TargetSurface == Enum.NormalId.Front then
                Block.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, gsize), roundToStep(Mouse.Hit.Position.Y, gsize)+DummyBlock.Size.Y/2, roundToStep(Mouse.Hit.Position.Z, gsize)-DummyBlock.Size.Z/2)
            elseif Mouse.TargetSurface == Enum.NormalId.Back then
                Block.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, gsize), roundToStep(Mouse.Hit.Position.Y, gsize)+DummyBlock.Size.Y/2, roundToStep(Mouse.Hit.Position.Z, gsize)+DummyBlock.Size.Z/2)
            else
                Block.Position = Vector3.new(roundToStep(Mouse.Hit.Position.X, gsize), roundToStep(Mouse.Hit.Position.Y, gsize)+DummyBlock.Size.Y/2, roundToStep(Mouse.Hit.Position.Z, gsize))
            end
        else
            Block:Destroy()
            DummyBlock.Color = Color3.fromRGB(255, 0, 0)
            wait(0.5)
            DummyBlock.Color = Color3.fromRGB(0, 68, 216)
        end--]]
        wait()
    elseif keycode.KeyCode == Enum.KeyCode.R then
        DummyBlock.CFrame = DummyBlock.CFrame * CFrame.Angles(0, math.rad(rot) ,0)
        wait()
    elseif keycode.KeyCode == Enum.KeyCode.T then
        DummyBlock.CFrame = DummyBlock.CFrame * CFrame.Angles(0 ,0 ,math.rad(rot))
        wait()
    end
end)

How would I fix this?

Any help would be appreciated

Answer this question