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

Make a Raycast stop if it is out of a region3?

Asked by 1 year ago
Edited 1 year ago

So basically I have a placement system however the placement system has a limit which

Players are limited to their own Tycoon house plot

So basically I want to get an idea of the math on how I can get raycast to stop if it ever tries to cross that boundary

And although I can use walls to block the raycast I don't think using walls are really efficient

I mean

it works but like

you need to create the walls and parts have size limits like 2048 i think

so anyways


To summarize

I want to limit a raycast to the set boundary that I have set

which is a square boundary

if it is past the boundary I want the model to be positioned onto the wall as if there is a part blocking the raycast

please ask me any other questions

TO CLARIFY IT EVEN MORE

THINK OF A PLACEMENT SYSTEM INSIDE OF A BOX

THE RAYCASTS WILL STOP BECAUSE THE RAYCAST HITS THE PART

NOW I AM TRYING TO PERFORM THIS WITHOUT THE PARTS USING ONLY RAYCAST

So anyways this is the code I have right now

local UserInputService = game:GetService("UserInputService")
local Plot = workspace.Plot



UserInputService.InputBegan:Connect(function(InputObject)
    local Position = InputObject.Position


    local Side1 = Plot.CFrame * CFrame.new(Plot.Size.X/2, 0, 0)
    local Side2 = Plot.CFrame * CFrame.new(Plot.Size.X/-2, 0, 0)
    local Side3 =  Plot.CFrame * CFrame.new(0, 0, Plot.Size.Z/2)
    local Side4 =  Plot.CFrame * CFrame.new(0, 0, Plot.Size.Z/-2)


    local ScreenPointToRay = workspace.CurrentCamera:ScreenPointToRay(Position.X, Position.Y)

    local Raycast1 = workspace:Raycast(ScreenPointToRay.Origin, ScreenPointToRay.Direction * 2000)



    if Raycast1 then

    else

        -- Raycast to the possible boundary



    end


end)
0
Please don't use so many newlines/breaks in your post Kingu_Criminal 205 — 1y
0
Have you tried using an invisible part to simulate a boundary? Kingu_Criminal 205 — 1y

Answer this question