How would I get the thickness of a part relative to where my raycast hit from?
You should probably elaborate. Do you mean the Size
, or something else?
Raycast
queries return the part they intersect, if there is one. Just grab the part data from the intersection and read its Size
.
1 Like
Here is a simple script that does what i assume u want
-- local script in StarterPlayerScripts
local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
Mouse.Button1Down:Connect(function()
local Direction = Mouse.UnitRay.Direction.Unit * 10000
local MousePos = Mouse.Origin.Position
local Params1 = RaycastParams.new()
Params1.FilterType,Params1.FilterDescendantsInstances = Enum.RaycastFilterType.Exclude,{Plr.Character}
local Hit1 = workspace:Raycast(MousePos,Direction,Params1)
if Hit1 then
if Hit1.Instance then
Hit1.Instance.Transparency = 0.5
local StartPosition = Hit1.Position
local Params2 = RaycastParams.new()
Params2.FilterType,Params2.FilterDescendantsInstances = Enum.RaycastFilterType.Include,{Hit1.Instance}
local Hit2 = workspace:Raycast(MousePos + Direction,-Direction,Params2)
if Hit2 then
local EndPosition = Hit2.Position
local Beam = Instance.new("Beam",Hit1.Instance)
Beam.Width0 = 0.1
Beam.Width1 = 0.1
Beam.FaceCamera = true
Beam.Color = ColorSequence.new(Color3.fromRGB(255,0,0))
local Att0 = Instance.new("Attachment",Hit1.Instance)
local Att1 = Instance.new("Attachment",Hit1.Instance)
Att0.WorldPosition = StartPosition
Att1.WorldPosition = EndPosition
Beam.Attachment0 = Att0
Beam.Attachment1 = Att1
print("Rays thickness is",(StartPosition - EndPosition).Magnitude,"studs")
end
end
end
end)
Example
This script creates a ray from players cameras position towards their mouse and once it hits a part, casts another ray from the opposite direction.
Now that we have the positions of both Rays hits, just get their magnitude!