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

How to Raycast and how to use camera:ScreenPointToCamera?

Asked by 3 years ago
Edited 3 years ago

Please Help me fix this, ive been trying to fix this in 6-7 Hours

`local player = game.Players.LocalPlayer local char = player.Character or player.CharacterAdded:Wait() local mouse = player:GetMouse() local camera = workspace.CurrentCamera

local mouseRay = mouse.UnitRay

local block = game.ReplicatedStorage.PlacementBlocksClientSide.StoneClient:Clone()

local runService = game:GetService("RunService") local uis = game:GetService("UserInputService")

local pframe = script.Parent.PlacementFrame local stoneButton = pframe.Stone

local function placement(X, Y) local params = RaycastParams.new() params.FilterDescendantsInstances = {block, char} params.FilterType = Enum.RaycastFilterType.Blacklist

local camray = camera:ScreenPointToRay(X, Y)

local rayCastResult = workspace:Raycast(camray.Origin, camray.Direction * 2048, params)

if not rayCastResult then return end

return rayCastResult.Instance, rayCastResult.Position

end

local mouseLocation = uis:GetMouseLocation()

stoneButton.MouseButton1Down:Connect(function() pframe.Visible = false

uis.InputBegan:Connect(function(m)
    if m.UserInputType == Enum.UserInputType.MouseButton1 then
        local mouseLocation = uis:GetMouseLocation()

        local target, position = placement(mouseLocation.X, mouseLocation.Y)

        if target and position then

            block.Parent = workspace
            block.CFrame = CFrame.new(position)
        end
    end
end)

runService.RenderStepped:Connect(function()
    local target, position = placement(mouseLocation.X, mouseLocation.Y)

    if target and position then
        block.Parent = workspace
        block.CFrame = CFrame.new(position)
    end

end)

end)`

0
I want Block follows my mouse netw0rkjans1 0 — 3y

Answer this question