How do I visualize a ray?

The problem is fairly simple, I just want to know how to visualize a ray with a part using the start position, end position and direction vector.

Any help is appreciated.

3 Likes

I have already read that, thank you. I just don’t know how to visualize it with a part.

If there is a passage that I missed, please let me know.

OP likely wants to see the ray while testing the project. Rays can come in different origins and directions.

@OP you can create a very thin part, position it at the origin of the ray. Have it look at the position, then offset it, because if you just position it at the origin of the ray it will be in the middle.

local r = Ray.new(origin, direction)
local _, position = workspace:FindPartOnRay(r)
local distance = (origin - position).Magnitude
local p = Instance.new("Part")
p.Anchored = true
p.CanCollide = false
p.Size = Vector3.new(0.1, 0.1, distance)
p.CFrame = lookAt(position, origin)*CFrame.new(0, 0, -distance/2)
-- for the lookAt() function, it is under CFrame.fromMatrix:
-- https://developer.roblox.com/en-us/api-reference/datatype/CFrame
15 Likes

How do I do this with WorldRoot:Raycast()?

2 Likes