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

How do I convert a UDim2 into a Vector3?

Asked by 3 years ago

I'm attempting a placement system, and I'm trying to get a vector3 position from a player's mouse position.

0
There is a property in the mouse which tells you cframe and position. read more about it here: https://developer.roblox.com/en-us/api-reference/class/Mouse munkuush 22 — 3y
0
Position is X and Y. promanfnatfreddys 20 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Use mouse.UnitRay and create a ray instead.

This is what i do in my script

-- Some variables are outside of this
RunService.Heartbeat:Connect(function()
                    local mouseRay = Mouse.UnitRay
                    RayInfo.FilterDescendantsInstances = {Tycoon, Character}
                    RayInfo.FilterType = Enum.RaycastFilterType.Blacklist

                    local raycastResult = game.Workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000)

                    if raycastResult then
                        local hit = raycastResult.Instance
                        if hit and not string.find(hit.Parent.Name, "Tycoon") then
                            if hit:IsA("Part") and hit.Name:lower() == "baseplate" then
                                goodToPlace = true
                                SetModelBrickColor(Tycoon, BrickColor.new("Bright green"))
                            else
                                goodToPlace = false
                                SetModelBrickColor(Tycoon, BrickColor.new("Really red"))
                            end

                            local Pos = raycastResult.Position

                            local X = Pos.X
                            local Y = Pos.Y
                            local Z = Pos.Z

                            X = Round(X)
                            Z = Round(Z)

                            local newCFrame = CFrame.new(X, Y + yBuildingOffset, Z)
                            Tycoon:SetPrimaryPartCFrame(newCFrame)

                        end
                    end
                end)
0
That didnt came out good MikkelCircled 42 — 3y
Ad

Answer this question